2 * Driver for Dell laptop extras
4 * Copyright (c) Red Hat <mjg@redhat.com>
6 * Based on documentation in the libsmbios package, Copyright (C) 2005 Dell
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/platform_device.h>
20 #include <linux/backlight.h>
21 #include <linux/err.h>
22 #include <linux/dmi.h>
24 #include <linux/power_supply.h>
25 #include <linux/acpi.h>
27 #include <linux/i8042.h>
28 #include <linux/slab.h>
29 #include <linux/debugfs.h>
30 #include <linux/seq_file.h>
31 #include "../../firmware/dcdbas.h"
33 #define BRIGHTNESS_TOKEN 0x7d
35 /* This structure will be modified by the firmware when we enter
36 * system management mode, hence the volatiles */
38 struct calling_interface_buffer {
41 volatile u32 input[4];
42 volatile u32 output[4];
45 struct calling_interface_token {
54 struct calling_interface_structure {
55 struct dmi_header header;
59 struct calling_interface_token tokens[];
66 static struct quirk_entry *quirks;
68 static struct quirk_entry quirk_dell_vostro_v130 = {
72 static int dmi_matched(const struct dmi_system_id *dmi)
74 quirks = dmi->driver_data;
78 static int da_command_address;
79 static int da_command_code;
80 static int da_num_tokens;
81 static struct calling_interface_token *da_tokens;
83 static struct platform_driver platform_driver = {
85 .name = "dell-laptop",
90 static struct platform_device *platform_device;
91 static struct backlight_device *dell_backlight_device;
93 static const struct dmi_system_id dell_device_table[] __initconst = {
95 .ident = "Dell laptop",
97 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
98 DMI_MATCH(DMI_CHASSIS_TYPE, "8"),
103 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
104 DMI_MATCH(DMI_CHASSIS_TYPE, "9"), /*Laptop*/
108 .ident = "Dell Computer Corporation",
110 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
111 DMI_MATCH(DMI_CHASSIS_TYPE, "8"),
116 MODULE_DEVICE_TABLE(dmi, dell_device_table);
118 static struct dmi_system_id __devinitdata dell_quirks[] = {
120 .callback = dmi_matched,
121 .ident = "Dell Vostro V130",
123 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
124 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V130"),
126 .driver_data = &quirk_dell_vostro_v130,
129 .callback = dmi_matched,
130 .ident = "Dell Vostro V131",
132 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
133 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"),
135 .driver_data = &quirk_dell_vostro_v130,
138 .callback = dmi_matched,
139 .ident = "Dell Vostro 3350",
141 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
142 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3350"),
144 .driver_data = &quirk_dell_vostro_v130,
147 .callback = dmi_matched,
148 .ident = "Dell Vostro 3555",
150 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
151 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3555"),
153 .driver_data = &quirk_dell_vostro_v130,
156 .callback = dmi_matched,
157 .ident = "Dell Inspiron N311z",
159 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
160 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron N311z"),
162 .driver_data = &quirk_dell_vostro_v130,
165 .callback = dmi_matched,
166 .ident = "Dell Inspiron M5110",
168 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
169 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron M5110"),
171 .driver_data = &quirk_dell_vostro_v130,
174 .callback = dmi_matched,
175 .ident = "Dell Vostro 3360",
177 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
178 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"),
180 .driver_data = &quirk_dell_vostro_v130,
183 .callback = dmi_matched,
184 .ident = "Dell Vostro 3460",
186 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
187 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3460"),
189 .driver_data = &quirk_dell_vostro_v130,
192 .callback = dmi_matched,
193 .ident = "Dell Vostro 3560",
195 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
196 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3560"),
198 .driver_data = &quirk_dell_vostro_v130,
201 .callback = dmi_matched,
202 .ident = "Dell Vostro 3450",
204 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
205 DMI_MATCH(DMI_PRODUCT_NAME, "Dell System Vostro 3450"),
207 .driver_data = &quirk_dell_vostro_v130,
212 static struct calling_interface_buffer *buffer;
213 static struct page *bufferpage;
214 static DEFINE_MUTEX(buffer_mutex);
216 static int hwswitch_state;
218 static void get_buffer(void)
220 mutex_lock(&buffer_mutex);
221 memset(buffer, 0, sizeof(struct calling_interface_buffer));
224 static void release_buffer(void)
226 mutex_unlock(&buffer_mutex);
229 static void __init parse_da_table(const struct dmi_header *dm)
231 /* Final token is a terminator, so we don't want to copy it */
232 int tokens = (dm->length-11)/sizeof(struct calling_interface_token)-1;
233 struct calling_interface_structure *table =
234 container_of(dm, struct calling_interface_structure, header);
236 /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least
242 da_command_address = table->cmdIOAddress;
243 da_command_code = table->cmdIOCode;
245 da_tokens = krealloc(da_tokens, (da_num_tokens + tokens) *
246 sizeof(struct calling_interface_token),
252 memcpy(da_tokens+da_num_tokens, table->tokens,
253 sizeof(struct calling_interface_token) * tokens);
255 da_num_tokens += tokens;
258 static void __init find_tokens(const struct dmi_header *dm, void *dummy)
261 case 0xd4: /* Indexed IO */
262 case 0xd5: /* Protected Area Type 1 */
263 case 0xd6: /* Protected Area Type 2 */
265 case 0xda: /* Calling interface */
271 static int find_token_location(int tokenid)
274 for (i = 0; i < da_num_tokens; i++) {
275 if (da_tokens[i].tokenID == tokenid)
276 return da_tokens[i].location;
282 static struct calling_interface_buffer *
283 dell_send_request(struct calling_interface_buffer *buffer, int class,
286 struct smi_cmd command;
288 command.magic = SMI_CMD_MAGIC;
289 command.command_address = da_command_address;
290 command.command_code = da_command_code;
291 command.ebx = virt_to_phys(buffer);
292 command.ecx = 0x42534931;
294 buffer->class = class;
295 buffer->select = select;
297 dcdbas_smi_request(&command);
302 static struct dentry *dell_laptop_dir;
304 static int dell_debugfs_show(struct seq_file *s, void *data)
309 dell_send_request(buffer, 17, 11);
310 status = buffer->output[1];
313 seq_printf(s, "status:\t0x%X\n", status);
314 seq_printf(s, "Bit 0 : Hardware switch supported: %lu\n",
316 seq_printf(s, "Bit 1 : Wifi locator supported: %lu\n",
317 (status & BIT(1)) >> 1);
318 seq_printf(s, "Bit 2 : Wifi is supported: %lu\n",
319 (status & BIT(2)) >> 2);
320 seq_printf(s, "Bit 3 : Bluetooth is supported: %lu\n",
321 (status & BIT(3)) >> 3);
322 seq_printf(s, "Bit 4 : WWAN is supported: %lu\n",
323 (status & BIT(4)) >> 4);
324 seq_printf(s, "Bit 5 : Wireless keyboard supported: %lu\n",
325 (status & BIT(5)) >> 5);
326 seq_printf(s, "Bit 8 : Wifi is installed: %lu\n",
327 (status & BIT(8)) >> 8);
328 seq_printf(s, "Bit 9 : Bluetooth is installed: %lu\n",
329 (status & BIT(9)) >> 9);
330 seq_printf(s, "Bit 10: WWAN is installed: %lu\n",
331 (status & BIT(10)) >> 10);
332 seq_printf(s, "Bit 16: Hardware switch is on: %lu\n",
333 (status & BIT(16)) >> 16);
334 seq_printf(s, "Bit 17: Wifi is blocked: %lu\n",
335 (status & BIT(17)) >> 17);
336 seq_printf(s, "Bit 18: Bluetooth is blocked: %lu\n",
337 (status & BIT(18)) >> 18);
338 seq_printf(s, "Bit 19: WWAN is blocked: %lu\n",
339 (status & BIT(19)) >> 19);
341 seq_printf(s, "\nhwswitch_state:\t0x%X\n", hwswitch_state);
342 seq_printf(s, "Bit 0 : Wifi controlled by switch: %lu\n",
343 hwswitch_state & BIT(0));
344 seq_printf(s, "Bit 1 : Bluetooth controlled by switch: %lu\n",
345 (hwswitch_state & BIT(1)) >> 1);
346 seq_printf(s, "Bit 2 : WWAN controlled by switch: %lu\n",
347 (hwswitch_state & BIT(2)) >> 2);
348 seq_printf(s, "Bit 7 : Wireless switch config locked: %lu\n",
349 (hwswitch_state & BIT(7)) >> 7);
350 seq_printf(s, "Bit 8 : Wifi locator enabled: %lu\n",
351 (hwswitch_state & BIT(8)) >> 8);
352 seq_printf(s, "Bit 15: Wifi locator setting locked: %lu\n",
353 (hwswitch_state & BIT(15)) >> 15);
358 static int dell_debugfs_open(struct inode *inode, struct file *file)
360 return single_open(file, dell_debugfs_show, inode->i_private);
363 static const struct file_operations dell_debugfs_fops = {
364 .owner = THIS_MODULE,
365 .open = dell_debugfs_open,
368 .release = single_release,
371 static int dell_send_intensity(struct backlight_device *bd)
376 buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
377 buffer->input[1] = bd->props.brightness;
379 if (buffer->input[0] == -1) {
384 if (power_supply_is_system_supplied() > 0)
385 dell_send_request(buffer, 1, 2);
387 dell_send_request(buffer, 1, 1);
394 static int dell_get_intensity(struct backlight_device *bd)
399 buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
401 if (buffer->input[0] == -1) {
406 if (power_supply_is_system_supplied() > 0)
407 dell_send_request(buffer, 0, 2);
409 dell_send_request(buffer, 0, 1);
411 ret = buffer->output[1];
418 static const struct backlight_ops dell_ops = {
419 .get_brightness = dell_get_intensity,
420 .update_status = dell_send_intensity,
423 static void touchpad_led_on(void)
427 i8042_command(&data, command | 1 << 12);
430 static void touchpad_led_off(void)
434 i8042_command(&data, command | 1 << 12);
437 static void touchpad_led_set(struct led_classdev *led_cdev,
438 enum led_brightness value)
446 static struct led_classdev touchpad_led = {
447 .name = "dell-laptop::touchpad",
448 .brightness_set = touchpad_led_set,
449 .flags = LED_CORE_SUSPENDRESUME,
452 static int __devinit touchpad_led_init(struct device *dev)
454 return led_classdev_register(dev, &touchpad_led);
457 static void touchpad_led_exit(void)
459 led_classdev_unregister(&touchpad_led);
462 static int __init dell_init(void)
464 int max_intensity = 0;
467 if (!dmi_check_system(dell_device_table))
471 /* find if this machine support other functions */
472 dmi_check_system(dell_quirks);
474 dmi_walk(find_tokens, NULL);
477 pr_info("Unable to find dmi tokens\n");
481 ret = platform_driver_register(&platform_driver);
483 goto fail_platform_driver;
484 platform_device = platform_device_alloc("dell-laptop", -1);
485 if (!platform_device) {
487 goto fail_platform_device1;
489 ret = platform_device_add(platform_device);
491 goto fail_platform_device2;
494 * Allocate buffer below 4GB for SMI data--only 32-bit physical addr
495 * is passed to SMI handler.
497 bufferpage = alloc_page(GFP_KERNEL | GFP_DMA32);
501 buffer = page_address(bufferpage);
503 if (quirks && quirks->touchpad_led)
504 touchpad_led_init(&platform_device->dev);
506 dell_laptop_dir = debugfs_create_dir("dell_laptop", NULL);
509 /* In the event of an ACPI backlight being available, don't
510 * register the platform controller.
512 if (acpi_video_backlight_support())
517 buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
518 if (buffer->input[0] != -1) {
519 dell_send_request(buffer, 0, 2);
520 max_intensity = buffer->output[3];
525 struct backlight_properties props;
526 memset(&props, 0, sizeof(struct backlight_properties));
527 props.type = BACKLIGHT_PLATFORM;
528 props.max_brightness = max_intensity;
529 dell_backlight_device = backlight_device_register("dell_backlight",
530 &platform_device->dev,
535 if (IS_ERR(dell_backlight_device)) {
536 ret = PTR_ERR(dell_backlight_device);
537 dell_backlight_device = NULL;
541 dell_backlight_device->props.brightness =
542 dell_get_intensity(dell_backlight_device);
543 backlight_update_status(dell_backlight_device);
549 free_page((unsigned long)bufferpage);
551 platform_device_del(platform_device);
552 fail_platform_device2:
553 platform_device_put(platform_device);
554 fail_platform_device1:
555 platform_driver_unregister(&platform_driver);
556 fail_platform_driver:
561 static void __exit dell_exit(void)
563 debugfs_remove_recursive(dell_laptop_dir);
564 if (quirks && quirks->touchpad_led)
566 backlight_device_unregister(dell_backlight_device);
567 if (platform_device) {
568 platform_device_unregister(platform_device);
569 platform_driver_unregister(&platform_driver);
572 free_page((unsigned long)buffer);
575 module_init(dell_init);
576 module_exit(dell_exit);
578 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
579 MODULE_DESCRIPTION("Dell laptop driver");
580 MODULE_LICENSE("GPL");