4 Copyright (C) 2007 Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
6 Copyright (C) 2003 Shane Spencer <shane@bogomip.com>
7 Adrian Yee <brewt-fujitsu@brewt.org>
9 Templated from msi-laptop.c which is copyright by its respective authors.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 * fujitsu-laptop.c - Fujitsu laptop support, providing access to additional
29 * features made available on a range of Fujitsu laptops including the
30 * P2xxx/P5xxx/S6xxx/S7xxx series.
32 * This driver exports a few files in /sys/devices/platform/fujitsu-laptop/;
33 * others may be added at a later date.
35 * lcd_level - Screen brightness: contains a single integer in the
38 * In addition to these platform device attributes the driver
39 * registers itself in the Linux backlight control subsystem and is
40 * available to userspace under /sys/class/backlight/fujitsu-laptop/.
42 * This driver has been tested on a Fujitsu Lifebook S7020. It should
43 * work on most P-series and S-series Lifebooks, but YMMV.
46 #include <linux/module.h>
47 #include <linux/kernel.h>
48 #include <linux/init.h>
49 #include <linux/acpi.h>
50 #include <linux/dmi.h>
51 #include <linux/backlight.h>
52 #include <linux/platform_device.h>
53 #include <linux/autoconf.h>
55 #define FUJITSU_DRIVER_VERSION "0.3"
57 #define FUJITSU_LCD_N_LEVELS 8
59 #define ACPI_FUJITSU_CLASS "fujitsu"
60 #define ACPI_FUJITSU_HID "FUJ02B1"
61 #define ACPI_FUJITSU_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI extras driver"
62 #define ACPI_FUJITSU_DEVICE_NAME "Fujitsu FUJ02B1"
65 acpi_handle acpi_handle
;
66 struct backlight_device
*bl_device
;
67 struct platform_device
*pf_device
;
69 unsigned long fuj02b1_state
;
70 unsigned int brightness_changed
;
71 unsigned int brightness_level
;
74 static struct fujitsu_t
*fujitsu
;
78 static int set_lcd_level(int level
)
80 acpi_status status
= AE_OK
;
81 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
82 struct acpi_object_list arg_list
= { 1, &arg0
};
83 acpi_handle handle
= NULL
;
85 if (level
< 0 || level
>= FUJITSU_LCD_N_LEVELS
)
91 status
= acpi_get_handle(fujitsu
->acpi_handle
, "SBLL", &handle
);
92 if (ACPI_FAILURE(status
)) {
93 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "SBLL not present\n"));
97 arg0
.integer
.value
= level
;
99 status
= acpi_evaluate_object(handle
, NULL
, &arg_list
, NULL
);
100 if (ACPI_FAILURE(status
))
106 static int get_lcd_level(void)
108 unsigned long state
= 0;
109 acpi_status status
= AE_OK
;
111 // Get the Brightness
113 acpi_evaluate_integer(fujitsu
->acpi_handle
, "GBLL", NULL
, &state
);
117 fujitsu
->fuj02b1_state
= state
;
118 fujitsu
->brightness_level
= state
& 0x0fffffff;
120 if (state
& 0x80000000)
121 fujitsu
->brightness_changed
= 1;
123 fujitsu
->brightness_changed
= 0;
125 return fujitsu
->brightness_level
;
128 /* Backlight device stuff */
130 static int bl_get_brightness(struct backlight_device
*b
)
132 return get_lcd_level();
135 static int bl_update_status(struct backlight_device
*b
)
137 return set_lcd_level(b
->props
.brightness
);
140 static struct backlight_ops fujitsubl_ops
= {
141 .get_brightness
= bl_get_brightness
,
142 .update_status
= bl_update_status
,
145 /* Platform device */
147 static ssize_t
show_lcd_level(struct device
*dev
,
148 struct device_attribute
*attr
, char *buf
)
153 ret
= get_lcd_level();
157 return sprintf(buf
, "%i\n", ret
);
160 static ssize_t
store_lcd_level(struct device
*dev
,
161 struct device_attribute
*attr
, const char *buf
,
167 if (sscanf(buf
, "%i", &level
) != 1
168 || (level
< 0 || level
>= FUJITSU_LCD_N_LEVELS
))
171 ret
= set_lcd_level(level
);
178 static DEVICE_ATTR(lcd_level
, 0644, show_lcd_level
, store_lcd_level
);
180 static struct attribute
*fujitsupf_attributes
[] = {
181 &dev_attr_lcd_level
.attr
,
185 static struct attribute_group fujitsupf_attribute_group
= {
186 .attrs
= fujitsupf_attributes
189 static struct platform_driver fujitsupf_driver
= {
191 .name
= "fujitsu-laptop",
192 .owner
= THIS_MODULE
,
198 static int acpi_fujitsu_add(struct acpi_device
*device
)
203 ACPI_FUNCTION_TRACE("acpi_fujitsu_add");
208 fujitsu
->acpi_handle
= device
->handle
;
209 sprintf(acpi_device_name(device
), "%s", ACPI_FUJITSU_DEVICE_NAME
);
210 sprintf(acpi_device_class(device
), "%s", ACPI_FUJITSU_CLASS
);
211 acpi_driver_data(device
) = fujitsu
;
213 result
= acpi_bus_get_power(fujitsu
->acpi_handle
, &state
);
215 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
216 "Error reading power state\n"));
220 printk(KERN_INFO PREFIX
"%s [%s] (%s)\n",
221 acpi_device_name(device
), acpi_device_bid(device
),
222 !device
->power
.state
? "on" : "off");
229 static int acpi_fujitsu_remove(struct acpi_device
*device
, int type
)
231 ACPI_FUNCTION_TRACE("acpi_fujitsu_remove");
233 if (!device
|| !acpi_driver_data(device
))
235 fujitsu
->acpi_handle
= 0;
240 static const struct acpi_device_id fujitsu_device_ids
[] = {
241 {ACPI_FUJITSU_HID
, 0},
245 static struct acpi_driver acpi_fujitsu_driver
= {
246 .name
= ACPI_FUJITSU_DRIVER_NAME
,
247 .class = ACPI_FUJITSU_CLASS
,
248 .ids
= fujitsu_device_ids
,
250 .add
= acpi_fujitsu_add
,
251 .remove
= acpi_fujitsu_remove
,
257 static int __init
fujitsu_init(void)
264 fujitsu
= kmalloc(sizeof(struct fujitsu_t
), GFP_KERNEL
);
267 memset(fujitsu
, 0, sizeof(struct fujitsu_t
));
269 result
= acpi_bus_register_driver(&acpi_fujitsu_driver
);
275 /* Register backlight stuff */
278 backlight_device_register("fujitsu-laptop", NULL
, NULL
,
280 if (IS_ERR(fujitsu
->bl_device
))
281 return PTR_ERR(fujitsu
->bl_device
);
283 fujitsu
->bl_device
->props
.max_brightness
= FUJITSU_LCD_N_LEVELS
- 1;
284 ret
= platform_driver_register(&fujitsupf_driver
);
288 /* Register platform stuff */
290 fujitsu
->pf_device
= platform_device_alloc("fujitsu-laptop", -1);
291 if (!fujitsu
->pf_device
) {
293 goto fail_platform_driver
;
296 ret
= platform_device_add(fujitsu
->pf_device
);
298 goto fail_platform_device1
;
301 sysfs_create_group(&fujitsu
->pf_device
->dev
.kobj
,
302 &fujitsupf_attribute_group
);
304 goto fail_platform_device2
;
306 printk(KERN_INFO
"fujitsu-laptop: driver " FUJITSU_DRIVER_VERSION
307 " successfully loaded.\n");
311 fail_platform_device2
:
313 platform_device_del(fujitsu
->pf_device
);
315 fail_platform_device1
:
317 platform_device_put(fujitsu
->pf_device
);
319 fail_platform_driver
:
321 platform_driver_unregister(&fujitsupf_driver
);
325 backlight_device_unregister(fujitsu
->bl_device
);
334 static void __exit
fujitsu_cleanup(void)
336 sysfs_remove_group(&fujitsu
->pf_device
->dev
.kobj
,
337 &fujitsupf_attribute_group
);
338 platform_device_unregister(fujitsu
->pf_device
);
339 platform_driver_unregister(&fujitsupf_driver
);
340 backlight_device_unregister(fujitsu
->bl_device
);
342 acpi_bus_unregister_driver(&acpi_fujitsu_driver
);
346 printk(KERN_INFO
"fujitsu-laptop: driver unloaded.\n");
349 module_init(fujitsu_init
);
350 module_exit(fujitsu_cleanup
);
352 MODULE_AUTHOR("Jonathan Woithe");
353 MODULE_DESCRIPTION("Fujitsu laptop extras support");
354 MODULE_VERSION(FUJITSU_DRIVER_VERSION
);
355 MODULE_LICENSE("GPL");