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;
128 return fujitsu
->brightness_level
;
131 /* Backlight device stuff */
133 static int bl_get_brightness(struct backlight_device
*b
)
135 return get_lcd_level();
138 static int bl_update_status(struct backlight_device
*b
)
140 return set_lcd_level(b
->props
.brightness
);
143 static struct backlight_ops fujitsubl_ops
= {
144 .get_brightness
= bl_get_brightness
,
145 .update_status
= bl_update_status
,
148 /* Platform device */
150 static ssize_t
show_lcd_level(struct device
*dev
,
151 struct device_attribute
*attr
, char *buf
)
156 ret
= get_lcd_level();
160 return sprintf(buf
, "%i\n", ret
);
163 static ssize_t
store_lcd_level(struct device
*dev
,
164 struct device_attribute
*attr
, const char *buf
,
170 if (sscanf(buf
, "%i", &level
) != 1
171 || (level
< 0 || level
>= FUJITSU_LCD_N_LEVELS
))
174 ret
= set_lcd_level(level
);
181 static DEVICE_ATTR(lcd_level
, 0644, show_lcd_level
, store_lcd_level
);
183 static struct attribute
*fujitsupf_attributes
[] = {
184 &dev_attr_lcd_level
.attr
,
188 static struct attribute_group fujitsupf_attribute_group
= {
189 .attrs
= fujitsupf_attributes
192 static struct platform_driver fujitsupf_driver
= {
194 .name
= "fujitsu-laptop",
195 .owner
= THIS_MODULE
,
201 int acpi_fujitsu_add(struct acpi_device
*device
)
206 ACPI_FUNCTION_TRACE("acpi_fujitsu_add");
211 fujitsu
->acpi_handle
= device
->handle
;
212 sprintf(acpi_device_name(device
), "%s", ACPI_FUJITSU_DEVICE_NAME
);
213 sprintf(acpi_device_class(device
), "%s", ACPI_FUJITSU_CLASS
);
214 acpi_driver_data(device
) = fujitsu
;
216 result
= acpi_bus_get_power(fujitsu
->acpi_handle
, &state
);
218 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
219 "Error reading power state\n"));
223 printk(KERN_INFO PREFIX
"%s [%s] (%s)\n",
224 acpi_device_name(device
), acpi_device_bid(device
),
225 !device
->power
.state
? "on" : "off");
232 int acpi_fujitsu_remove(struct acpi_device
*device
, int type
)
234 ACPI_FUNCTION_TRACE("acpi_fujitsu_remove");
236 if (!device
|| !acpi_driver_data(device
))
238 fujitsu
->acpi_handle
= 0;
243 static const struct acpi_device_id fujitsu_device_ids
[] = {
244 {ACPI_FUJITSU_HID
, 0},
248 static struct acpi_driver acpi_fujitsu_driver
= {
249 .name
= ACPI_FUJITSU_DRIVER_NAME
,
250 .class = ACPI_FUJITSU_CLASS
,
251 .ids
= fujitsu_device_ids
,
253 .add
= acpi_fujitsu_add
,
254 .remove
= acpi_fujitsu_remove
,
260 static int __init
fujitsu_init(void)
267 fujitsu
= kmalloc(sizeof(struct fujitsu_t
), GFP_KERNEL
);
270 memset(fujitsu
, 0, sizeof(struct fujitsu_t
));
272 result
= acpi_bus_register_driver(&acpi_fujitsu_driver
);
278 /* Register backlight stuff */
281 backlight_device_register("fujitsu-laptop", NULL
, NULL
,
283 if (IS_ERR(fujitsu
->bl_device
))
284 return PTR_ERR(fujitsu
->bl_device
);
286 fujitsu
->bl_device
->props
.max_brightness
= FUJITSU_LCD_N_LEVELS
- 1;
287 ret
= platform_driver_register(&fujitsupf_driver
);
291 /* Register platform stuff */
293 fujitsu
->pf_device
= platform_device_alloc("fujitsu-laptop", -1);
294 if (!fujitsu
->pf_device
) {
296 goto fail_platform_driver
;
299 ret
= platform_device_add(fujitsu
->pf_device
);
301 goto fail_platform_device1
;
304 sysfs_create_group(&fujitsu
->pf_device
->dev
.kobj
,
305 &fujitsupf_attribute_group
);
307 goto fail_platform_device2
;
309 printk(KERN_INFO
"fujitsu-laptop: driver " FUJITSU_DRIVER_VERSION
310 " successfully loaded.\n");
314 fail_platform_device2
:
316 platform_device_del(fujitsu
->pf_device
);
318 fail_platform_device1
:
320 platform_device_put(fujitsu
->pf_device
);
322 fail_platform_driver
:
324 platform_driver_unregister(&fujitsupf_driver
);
328 backlight_device_unregister(fujitsu
->bl_device
);
337 static void __exit
fujitsu_cleanup(void)
339 sysfs_remove_group(&fujitsu
->pf_device
->dev
.kobj
,
340 &fujitsupf_attribute_group
);
341 platform_device_unregister(fujitsu
->pf_device
);
342 platform_driver_unregister(&fujitsupf_driver
);
343 backlight_device_unregister(fujitsu
->bl_device
);
345 acpi_bus_unregister_driver(&acpi_fujitsu_driver
);
349 printk(KERN_INFO
"fujitsu-laptop: driver unloaded.\n");
352 module_init(fujitsu_init
);
353 module_exit(fujitsu_cleanup
);
355 MODULE_AUTHOR("Jonathan Woithe");
356 MODULE_DESCRIPTION("Fujitsu laptop extras support");
357 MODULE_VERSION(FUJITSU_DRIVER_VERSION
);
358 MODULE_LICENSE("GPL");