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 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/backlight.h>
19 #include <linux/err.h>
20 #include <linux/dmi.h>
22 #include <linux/rfkill.h>
23 #include <linux/power_supply.h>
24 #include <linux/acpi.h>
26 #include <linux/i8042.h>
27 #include <linux/slab.h>
28 #include "../../firmware/dcdbas.h"
30 #define BRIGHTNESS_TOKEN 0x7d
32 /* This structure will be modified by the firmware when we enter
33 * system management mode, hence the volatiles */
35 struct calling_interface_buffer
{
38 volatile u32 input
[4];
39 volatile u32 output
[4];
42 struct calling_interface_token
{
51 struct calling_interface_structure
{
52 struct dmi_header header
;
56 struct calling_interface_token tokens
[];
59 static int da_command_address
;
60 static int da_command_code
;
61 static int da_num_tokens
;
62 static struct calling_interface_token
*da_tokens
;
64 static struct platform_driver platform_driver
= {
66 .name
= "dell-laptop",
71 static struct platform_device
*platform_device
;
72 static struct backlight_device
*dell_backlight_device
;
73 static struct rfkill
*wifi_rfkill
;
74 static struct rfkill
*bluetooth_rfkill
;
75 static struct rfkill
*wwan_rfkill
;
77 static const struct dmi_system_id __initdata dell_device_table
[] = {
79 .ident
= "Dell laptop",
81 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
82 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
86 .ident
= "Dell Computer Corporation",
88 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Computer Corporation"),
89 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
95 static struct dmi_system_id __devinitdata dell_blacklist
[] = {
96 /* Supported by compal-laptop */
98 .ident
= "Dell Mini 9",
100 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
101 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 910"),
105 .ident
= "Dell Mini 10",
107 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
108 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 1010"),
112 .ident
= "Dell Mini 10v",
114 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
115 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 1011"),
119 .ident
= "Dell Inspiron 11z",
121 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
122 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 1110"),
126 .ident
= "Dell Mini 12",
128 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
129 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 1210"),
135 static struct calling_interface_buffer
*buffer
;
136 static struct page
*bufferpage
;
137 static DEFINE_MUTEX(buffer_mutex
);
139 static int hwswitch_state
;
141 static void get_buffer(void)
143 mutex_lock(&buffer_mutex
);
144 memset(buffer
, 0, sizeof(struct calling_interface_buffer
));
147 static void release_buffer(void)
149 mutex_unlock(&buffer_mutex
);
152 static void __init
parse_da_table(const struct dmi_header
*dm
)
154 /* Final token is a terminator, so we don't want to copy it */
155 int tokens
= (dm
->length
-11)/sizeof(struct calling_interface_token
)-1;
156 struct calling_interface_structure
*table
=
157 container_of(dm
, struct calling_interface_structure
, header
);
159 /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least
165 da_command_address
= table
->cmdIOAddress
;
166 da_command_code
= table
->cmdIOCode
;
168 da_tokens
= krealloc(da_tokens
, (da_num_tokens
+ tokens
) *
169 sizeof(struct calling_interface_token
),
175 memcpy(da_tokens
+da_num_tokens
, table
->tokens
,
176 sizeof(struct calling_interface_token
) * tokens
);
178 da_num_tokens
+= tokens
;
181 static void __init
find_tokens(const struct dmi_header
*dm
, void *dummy
)
184 case 0xd4: /* Indexed IO */
186 case 0xd5: /* Protected Area Type 1 */
188 case 0xd6: /* Protected Area Type 2 */
190 case 0xda: /* Calling interface */
196 static int find_token_location(int tokenid
)
199 for (i
= 0; i
< da_num_tokens
; i
++) {
200 if (da_tokens
[i
].tokenID
== tokenid
)
201 return da_tokens
[i
].location
;
207 static struct calling_interface_buffer
*
208 dell_send_request(struct calling_interface_buffer
*buffer
, int class,
211 struct smi_cmd command
;
213 command
.magic
= SMI_CMD_MAGIC
;
214 command
.command_address
= da_command_address
;
215 command
.command_code
= da_command_code
;
216 command
.ebx
= virt_to_phys(buffer
);
217 command
.ecx
= 0x42534931;
219 buffer
->class = class;
220 buffer
->select
= select
;
222 dcdbas_smi_request(&command
);
227 /* Derived from information in DellWirelessCtl.cpp:
228 Class 17, select 11 is radio control. It returns an array of 32-bit values.
230 Input byte 0 = 0: Wireless information
232 result[0]: return code
234 Bit 0: Hardware switch supported
235 Bit 1: Wifi locator supported
236 Bit 2: Wifi is supported
237 Bit 3: Bluetooth is supported
238 Bit 4: WWAN is supported
239 Bit 5: Wireless keyboard supported
241 Bit 8: Wifi is installed
242 Bit 9: Bluetooth is installed
243 Bit 10: WWAN is installed
245 Bit 16: Hardware switch is on
246 Bit 17: Wifi is blocked
247 Bit 18: Bluetooth is blocked
248 Bit 19: WWAN is blocked
250 result[2]: NVRAM size in bytes
251 result[3]: NVRAM format version number
253 Input byte 0 = 2: Wireless switch configuration
254 result[0]: return code
256 Bit 0: Wifi controlled by switch
257 Bit 1: Bluetooth controlled by switch
258 Bit 2: WWAN controlled by switch
260 Bit 7: Wireless switch config locked
261 Bit 8: Wifi locator enabled
263 Bit 15: Wifi locator setting locked
267 static int dell_rfkill_set(void *data
, bool blocked
)
269 int disable
= blocked
? 1 : 0;
270 unsigned long radio
= (unsigned long)data
;
271 int hwswitch_bit
= (unsigned long)data
- 1;
275 dell_send_request(buffer
, 17, 11);
277 /* If the hardware switch controls this radio, and the hardware
278 switch is disabled, don't allow changing the software state */
279 if ((hwswitch_state
& BIT(hwswitch_bit
)) &&
280 !(buffer
->output
[1] & BIT(16))) {
285 buffer
->input
[0] = (1 | (radio
<<8) | (disable
<< 16));
286 dell_send_request(buffer
, 17, 11);
293 static void dell_rfkill_query(struct rfkill
*rfkill
, void *data
)
296 int bit
= (unsigned long)data
+ 16;
297 int hwswitch_bit
= (unsigned long)data
- 1;
300 dell_send_request(buffer
, 17, 11);
301 status
= buffer
->output
[1];
304 rfkill_set_sw_state(rfkill
, !!(status
& BIT(bit
)));
306 if (hwswitch_state
& (BIT(hwswitch_bit
)))
307 rfkill_set_hw_state(rfkill
, !(status
& BIT(16)));
310 static const struct rfkill_ops dell_rfkill_ops
= {
311 .set_block
= dell_rfkill_set
,
312 .query
= dell_rfkill_query
,
315 static void dell_update_rfkill(struct work_struct
*ignored
)
318 dell_rfkill_query(wifi_rfkill
, (void *)1);
319 if (bluetooth_rfkill
)
320 dell_rfkill_query(bluetooth_rfkill
, (void *)2);
322 dell_rfkill_query(wwan_rfkill
, (void *)3);
324 static DECLARE_DELAYED_WORK(dell_rfkill_work
, dell_update_rfkill
);
327 static int __init
dell_setup_rfkill(void)
332 if (dmi_check_system(dell_blacklist
)) {
333 printk(KERN_INFO
"dell-laptop: Blacklisted hardware detected - "
334 "not enabling rfkill\n");
339 dell_send_request(buffer
, 17, 11);
340 status
= buffer
->output
[1];
341 buffer
->input
[0] = 0x2;
342 dell_send_request(buffer
, 17, 11);
343 hwswitch_state
= buffer
->output
[1];
346 if ((status
& (1<<2|1<<8)) == (1<<2|1<<8)) {
347 wifi_rfkill
= rfkill_alloc("dell-wifi", &platform_device
->dev
,
349 &dell_rfkill_ops
, (void *) 1);
354 ret
= rfkill_register(wifi_rfkill
);
359 if ((status
& (1<<3|1<<9)) == (1<<3|1<<9)) {
360 bluetooth_rfkill
= rfkill_alloc("dell-bluetooth",
361 &platform_device
->dev
,
362 RFKILL_TYPE_BLUETOOTH
,
363 &dell_rfkill_ops
, (void *) 2);
364 if (!bluetooth_rfkill
) {
368 ret
= rfkill_register(bluetooth_rfkill
);
373 if ((status
& (1<<4|1<<10)) == (1<<4|1<<10)) {
374 wwan_rfkill
= rfkill_alloc("dell-wwan",
375 &platform_device
->dev
,
377 &dell_rfkill_ops
, (void *) 3);
382 ret
= rfkill_register(wwan_rfkill
);
389 rfkill_destroy(wwan_rfkill
);
390 if (bluetooth_rfkill
)
391 rfkill_unregister(bluetooth_rfkill
);
393 rfkill_destroy(bluetooth_rfkill
);
395 rfkill_unregister(wifi_rfkill
);
397 rfkill_destroy(wifi_rfkill
);
402 static void dell_cleanup_rfkill(void)
405 rfkill_unregister(wifi_rfkill
);
406 rfkill_destroy(wifi_rfkill
);
408 if (bluetooth_rfkill
) {
409 rfkill_unregister(bluetooth_rfkill
);
410 rfkill_destroy(bluetooth_rfkill
);
413 rfkill_unregister(wwan_rfkill
);
414 rfkill_destroy(wwan_rfkill
);
418 static int dell_send_intensity(struct backlight_device
*bd
)
423 buffer
->input
[0] = find_token_location(BRIGHTNESS_TOKEN
);
424 buffer
->input
[1] = bd
->props
.brightness
;
426 if (buffer
->input
[0] == -1) {
431 if (power_supply_is_system_supplied() > 0)
432 dell_send_request(buffer
, 1, 2);
434 dell_send_request(buffer
, 1, 1);
441 static int dell_get_intensity(struct backlight_device
*bd
)
446 buffer
->input
[0] = find_token_location(BRIGHTNESS_TOKEN
);
448 if (buffer
->input
[0] == -1) {
453 if (power_supply_is_system_supplied() > 0)
454 dell_send_request(buffer
, 0, 2);
456 dell_send_request(buffer
, 0, 1);
462 return buffer
->output
[1];
465 static struct backlight_ops dell_ops
= {
466 .get_brightness
= dell_get_intensity
,
467 .update_status
= dell_send_intensity
,
470 bool dell_laptop_i8042_filter(unsigned char data
, unsigned char str
,
473 static bool extended
;
478 if (unlikely(data
== 0xe0)) {
481 } else if (unlikely(extended
)) {
484 schedule_delayed_work(&dell_rfkill_work
,
485 round_jiffies_relative(HZ
));
494 static int __init
dell_init(void)
496 int max_intensity
= 0;
499 if (!dmi_check_system(dell_device_table
))
502 dmi_walk(find_tokens
, NULL
);
505 printk(KERN_INFO
"dell-laptop: Unable to find dmi tokens\n");
509 ret
= platform_driver_register(&platform_driver
);
511 goto fail_platform_driver
;
512 platform_device
= platform_device_alloc("dell-laptop", -1);
513 if (!platform_device
) {
515 goto fail_platform_device1
;
517 ret
= platform_device_add(platform_device
);
519 goto fail_platform_device2
;
522 * Allocate buffer below 4GB for SMI data--only 32-bit physical addr
523 * is passed to SMI handler.
525 bufferpage
= alloc_page(GFP_KERNEL
| GFP_DMA32
);
529 buffer
= page_address(bufferpage
);
530 mutex_init(&buffer_mutex
);
532 ret
= dell_setup_rfkill();
535 printk(KERN_WARNING
"dell-laptop: Unable to setup rfkill\n");
539 ret
= i8042_install_filter(dell_laptop_i8042_filter
);
542 "dell-laptop: Unable to install key filter\n");
547 /* In the event of an ACPI backlight being available, don't
548 * register the platform controller.
550 if (acpi_video_backlight_support())
555 buffer
->input
[0] = find_token_location(BRIGHTNESS_TOKEN
);
556 if (buffer
->input
[0] != -1) {
557 dell_send_request(buffer
, 0, 2);
558 max_intensity
= buffer
->output
[3];
563 struct backlight_properties props
;
564 memset(&props
, 0, sizeof(struct backlight_properties
));
565 props
.max_brightness
= max_intensity
;
566 dell_backlight_device
= backlight_device_register("dell_backlight",
567 &platform_device
->dev
,
572 if (IS_ERR(dell_backlight_device
)) {
573 ret
= PTR_ERR(dell_backlight_device
);
574 dell_backlight_device
= NULL
;
578 dell_backlight_device
->props
.brightness
=
579 dell_get_intensity(dell_backlight_device
);
580 backlight_update_status(dell_backlight_device
);
586 i8042_remove_filter(dell_laptop_i8042_filter
);
587 cancel_delayed_work_sync(&dell_rfkill_work
);
589 dell_cleanup_rfkill();
591 free_page((unsigned long)bufferpage
);
593 platform_device_del(platform_device
);
594 fail_platform_device2
:
595 platform_device_put(platform_device
);
596 fail_platform_device1
:
597 platform_driver_unregister(&platform_driver
);
598 fail_platform_driver
:
603 static void __exit
dell_exit(void)
605 i8042_remove_filter(dell_laptop_i8042_filter
);
606 cancel_delayed_work_sync(&dell_rfkill_work
);
607 backlight_device_unregister(dell_backlight_device
);
608 dell_cleanup_rfkill();
609 if (platform_device
) {
610 platform_device_unregister(platform_device
);
611 platform_driver_unregister(&platform_driver
);
614 free_page((unsigned long)buffer
);
617 module_init(dell_init
);
618 module_exit(dell_exit
);
620 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
621 MODULE_DESCRIPTION("Dell laptop driver");
622 MODULE_LICENSE("GPL");
623 MODULE_ALIAS("dmi:*svnDellInc.:*:ct8:*");
624 MODULE_ALIAS("dmi:*svnDellComputerCorporation.:*:ct8:*");