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>
54 #define FUJITSU_DRIVER_VERSION "0.3"
56 #define FUJITSU_LCD_N_LEVELS 8
58 #define ACPI_FUJITSU_CLASS "fujitsu"
59 #define ACPI_FUJITSU_HID "FUJ02B1"
60 #define ACPI_FUJITSU_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI extras driver"
61 #define ACPI_FUJITSU_DEVICE_NAME "Fujitsu FUJ02B1"
64 acpi_handle acpi_handle;
65 struct backlight_device *bl_device;
66 struct platform_device *pf_device;
68 unsigned long fuj02b1_state;
69 unsigned int brightness_changed;
70 unsigned int brightness_level;
73 static struct fujitsu_t *fujitsu;
77 static int set_lcd_level(int level)
79 acpi_status status = AE_OK;
80 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
81 struct acpi_object_list arg_list = { 1, &arg0 };
82 acpi_handle handle = NULL;
84 if (level < 0 || level >= FUJITSU_LCD_N_LEVELS)
90 status = acpi_get_handle(fujitsu->acpi_handle, "SBLL", &handle);
91 if (ACPI_FAILURE(status)) {
92 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "SBLL not present\n"));
96 arg0.integer.value = level;
98 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
99 if (ACPI_FAILURE(status))
105 static int get_lcd_level(void)
107 unsigned long state = 0;
108 acpi_status status = AE_OK;
110 // Get the Brightness
112 acpi_evaluate_integer(fujitsu->acpi_handle, "GBLL", NULL, &state);
116 fujitsu->fuj02b1_state = state;
117 fujitsu->brightness_level = state & 0x0fffffff;
119 if (state & 0x80000000)
120 fujitsu->brightness_changed = 1;
122 fujitsu->brightness_changed = 0;
124 return fujitsu->brightness_level;
127 /* Backlight device stuff */
129 static int bl_get_brightness(struct backlight_device *b)
131 return get_lcd_level();
134 static int bl_update_status(struct backlight_device *b)
136 return set_lcd_level(b->props.brightness);
139 static struct backlight_ops fujitsubl_ops = {
140 .get_brightness = bl_get_brightness,
141 .update_status = bl_update_status,
144 /* Platform device */
146 static ssize_t show_lcd_level(struct device *dev,
147 struct device_attribute *attr, char *buf)
152 ret = get_lcd_level();
156 return sprintf(buf, "%i\n", ret);
159 static ssize_t store_lcd_level(struct device *dev,
160 struct device_attribute *attr, const char *buf,
166 if (sscanf(buf, "%i", &level) != 1
167 || (level < 0 || level >= FUJITSU_LCD_N_LEVELS))
170 ret = set_lcd_level(level);
177 static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level);
179 static struct attribute *fujitsupf_attributes[] = {
180 &dev_attr_lcd_level.attr,
184 static struct attribute_group fujitsupf_attribute_group = {
185 .attrs = fujitsupf_attributes
188 static struct platform_driver fujitsupf_driver = {
190 .name = "fujitsu-laptop",
191 .owner = THIS_MODULE,
197 static int acpi_fujitsu_add(struct acpi_device *device)
202 ACPI_FUNCTION_TRACE("acpi_fujitsu_add");
207 fujitsu->acpi_handle = device->handle;
208 sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_DEVICE_NAME);
209 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
210 acpi_driver_data(device) = fujitsu;
212 result = acpi_bus_get_power(fujitsu->acpi_handle, &state);
214 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
215 "Error reading power state\n"));
219 printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
220 acpi_device_name(device), acpi_device_bid(device),
221 !device->power.state ? "on" : "off");
228 static int acpi_fujitsu_remove(struct acpi_device *device, int type)
230 ACPI_FUNCTION_TRACE("acpi_fujitsu_remove");
232 if (!device || !acpi_driver_data(device))
234 fujitsu->acpi_handle = NULL;
239 static const struct acpi_device_id fujitsu_device_ids[] = {
240 {ACPI_FUJITSU_HID, 0},
244 static struct acpi_driver acpi_fujitsu_driver = {
245 .name = ACPI_FUJITSU_DRIVER_NAME,
246 .class = ACPI_FUJITSU_CLASS,
247 .ids = fujitsu_device_ids,
249 .add = acpi_fujitsu_add,
250 .remove = acpi_fujitsu_remove,
256 static int __init fujitsu_init(void)
263 fujitsu = kmalloc(sizeof(struct fujitsu_t), GFP_KERNEL);
266 memset(fujitsu, 0, sizeof(struct fujitsu_t));
268 result = acpi_bus_register_driver(&acpi_fujitsu_driver);
274 /* Register backlight stuff */
277 backlight_device_register("fujitsu-laptop", NULL, NULL,
279 if (IS_ERR(fujitsu->bl_device))
280 return PTR_ERR(fujitsu->bl_device);
282 fujitsu->bl_device->props.max_brightness = FUJITSU_LCD_N_LEVELS - 1;
283 ret = platform_driver_register(&fujitsupf_driver);
287 /* Register platform stuff */
289 fujitsu->pf_device = platform_device_alloc("fujitsu-laptop", -1);
290 if (!fujitsu->pf_device) {
292 goto fail_platform_driver;
295 ret = platform_device_add(fujitsu->pf_device);
297 goto fail_platform_device1;
300 sysfs_create_group(&fujitsu->pf_device->dev.kobj,
301 &fujitsupf_attribute_group);
303 goto fail_platform_device2;
305 printk(KERN_INFO "fujitsu-laptop: driver " FUJITSU_DRIVER_VERSION
306 " successfully loaded.\n");
310 fail_platform_device2:
312 platform_device_del(fujitsu->pf_device);
314 fail_platform_device1:
316 platform_device_put(fujitsu->pf_device);
318 fail_platform_driver:
320 platform_driver_unregister(&fujitsupf_driver);
324 backlight_device_unregister(fujitsu->bl_device);
333 static void __exit fujitsu_cleanup(void)
335 sysfs_remove_group(&fujitsu->pf_device->dev.kobj,
336 &fujitsupf_attribute_group);
337 platform_device_unregister(fujitsu->pf_device);
338 platform_driver_unregister(&fujitsupf_driver);
339 backlight_device_unregister(fujitsu->bl_device);
341 acpi_bus_unregister_driver(&acpi_fujitsu_driver);
345 printk(KERN_INFO "fujitsu-laptop: driver unloaded.\n");
348 module_init(fujitsu_init);
349 module_exit(fujitsu_cleanup);
351 MODULE_AUTHOR("Jonathan Woithe");
352 MODULE_DESCRIPTION("Fujitsu laptop extras support");
353 MODULE_VERSION(FUJITSU_DRIVER_VERSION);
354 MODULE_LICENSE("GPL");
356 static struct pnp_device_id pnp_ids[] = {
360 MODULE_DEVICE_TABLE(pnp, pnp_ids);