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 "../../firmware/dcdbas.h"
29 #define BRIGHTNESS_TOKEN 0x7d
31 /* This structure will be modified by the firmware when we enter
32 * system management mode, hence the volatiles */
34 struct calling_interface_buffer
{
37 volatile u32 input
[4];
38 volatile u32 output
[4];
41 struct calling_interface_token
{
50 struct calling_interface_structure
{
51 struct dmi_header header
;
55 struct calling_interface_token tokens
[];
58 static int da_command_address
;
59 static int da_command_code
;
60 static int da_num_tokens
;
61 static struct calling_interface_token
*da_tokens
;
63 static struct platform_driver platform_driver
= {
65 .name
= "dell-laptop",
70 static struct platform_device
*platform_device
;
71 static struct backlight_device
*dell_backlight_device
;
72 static struct rfkill
*wifi_rfkill
;
73 static struct rfkill
*bluetooth_rfkill
;
74 static struct rfkill
*wwan_rfkill
;
76 static const struct dmi_system_id __initdata dell_device_table
[] = {
78 .ident
= "Dell laptop",
80 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
81 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
85 .ident
= "Dell Computer Corporation",
87 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Computer Corporation"),
88 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
94 static struct dmi_system_id __devinitdata dell_blacklist
[] = {
95 /* Supported by compal-laptop */
97 .ident
= "Dell Mini 9",
99 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
100 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 910"),
104 .ident
= "Dell Mini 10",
106 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
107 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 1010"),
111 .ident
= "Dell Mini 10v",
113 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
114 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 1011"),
118 .ident
= "Dell Inspiron 11z",
120 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
121 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 1110"),
125 .ident
= "Dell Mini 12",
127 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
128 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 1210"),
134 static struct calling_interface_buffer
*buffer
;
135 static struct page
*bufferpage
;
136 static DEFINE_MUTEX(buffer_mutex
);
138 static int hwswitch_state
;
140 static void get_buffer(void)
142 mutex_lock(&buffer_mutex
);
143 memset(buffer
, 0, sizeof(struct calling_interface_buffer
));
146 static void release_buffer(void)
148 mutex_unlock(&buffer_mutex
);
151 static void __init
parse_da_table(const struct dmi_header
*dm
)
153 /* Final token is a terminator, so we don't want to copy it */
154 int tokens
= (dm
->length
-11)/sizeof(struct calling_interface_token
)-1;
155 struct calling_interface_structure
*table
=
156 container_of(dm
, struct calling_interface_structure
, header
);
158 /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least
164 da_command_address
= table
->cmdIOAddress
;
165 da_command_code
= table
->cmdIOCode
;
167 da_tokens
= krealloc(da_tokens
, (da_num_tokens
+ tokens
) *
168 sizeof(struct calling_interface_token
),
174 memcpy(da_tokens
+da_num_tokens
, table
->tokens
,
175 sizeof(struct calling_interface_token
) * tokens
);
177 da_num_tokens
+= tokens
;
180 static void __init
find_tokens(const struct dmi_header
*dm
, void *dummy
)
183 case 0xd4: /* Indexed IO */
185 case 0xd5: /* Protected Area Type 1 */
187 case 0xd6: /* Protected Area Type 2 */
189 case 0xda: /* Calling interface */
195 static int find_token_location(int tokenid
)
198 for (i
= 0; i
< da_num_tokens
; i
++) {
199 if (da_tokens
[i
].tokenID
== tokenid
)
200 return da_tokens
[i
].location
;
206 static struct calling_interface_buffer
*
207 dell_send_request(struct calling_interface_buffer
*buffer
, int class,
210 struct smi_cmd command
;
212 command
.magic
= SMI_CMD_MAGIC
;
213 command
.command_address
= da_command_address
;
214 command
.command_code
= da_command_code
;
215 command
.ebx
= virt_to_phys(buffer
);
216 command
.ecx
= 0x42534931;
218 buffer
->class = class;
219 buffer
->select
= select
;
221 dcdbas_smi_request(&command
);
226 /* Derived from information in DellWirelessCtl.cpp:
227 Class 17, select 11 is radio control. It returns an array of 32-bit values.
229 Input byte 0 = 0: Wireless information
231 result[0]: return code
233 Bit 0: Hardware switch supported
234 Bit 1: Wifi locator supported
235 Bit 2: Wifi is supported
236 Bit 3: Bluetooth is supported
237 Bit 4: WWAN is supported
238 Bit 5: Wireless keyboard supported
240 Bit 8: Wifi is installed
241 Bit 9: Bluetooth is installed
242 Bit 10: WWAN is installed
244 Bit 16: Hardware switch is on
245 Bit 17: Wifi is blocked
246 Bit 18: Bluetooth is blocked
247 Bit 19: WWAN is blocked
249 result[2]: NVRAM size in bytes
250 result[3]: NVRAM format version number
252 Input byte 0 = 2: Wireless switch configuration
253 result[0]: return code
255 Bit 0: Wifi controlled by switch
256 Bit 1: Bluetooth controlled by switch
257 Bit 2: WWAN controlled by switch
259 Bit 7: Wireless switch config locked
260 Bit 8: Wifi locator enabled
262 Bit 15: Wifi locator setting locked
266 static int dell_rfkill_set(void *data
, bool blocked
)
268 int disable
= blocked
? 1 : 0;
269 unsigned long radio
= (unsigned long)data
;
270 int hwswitch_bit
= (unsigned long)data
- 1;
274 dell_send_request(buffer
, 17, 11);
276 /* If the hardware switch controls this radio, and the hardware
277 switch is disabled, don't allow changing the software state */
278 if ((hwswitch_state
& BIT(hwswitch_bit
)) &&
279 !(buffer
->output
[1] & BIT(16))) {
284 buffer
->input
[0] = (1 | (radio
<<8) | (disable
<< 16));
285 dell_send_request(buffer
, 17, 11);
292 static void dell_rfkill_query(struct rfkill
*rfkill
, void *data
)
295 int bit
= (unsigned long)data
+ 16;
296 int hwswitch_bit
= (unsigned long)data
- 1;
299 dell_send_request(buffer
, 17, 11);
300 status
= buffer
->output
[1];
303 rfkill_set_sw_state(rfkill
, !!(status
& BIT(bit
)));
305 if (hwswitch_state
& (BIT(hwswitch_bit
)))
306 rfkill_set_hw_state(rfkill
, !(status
& BIT(16)));
309 static const struct rfkill_ops dell_rfkill_ops
= {
310 .set_block
= dell_rfkill_set
,
311 .query
= dell_rfkill_query
,
314 static void dell_update_rfkill(struct work_struct
*ignored
)
317 dell_rfkill_query(wifi_rfkill
, (void *)1);
318 if (bluetooth_rfkill
)
319 dell_rfkill_query(bluetooth_rfkill
, (void *)2);
321 dell_rfkill_query(wwan_rfkill
, (void *)3);
323 static DECLARE_DELAYED_WORK(dell_rfkill_work
, dell_update_rfkill
);
326 static int __init
dell_setup_rfkill(void)
331 if (dmi_check_system(dell_blacklist
)) {
332 printk(KERN_INFO
"dell-laptop: Blacklisted hardware detected - "
333 "not enabling rfkill\n");
338 dell_send_request(buffer
, 17, 11);
339 status
= buffer
->output
[1];
340 buffer
->input
[0] = 0x2;
341 dell_send_request(buffer
, 17, 11);
342 hwswitch_state
= buffer
->output
[1];
345 if ((status
& (1<<2|1<<8)) == (1<<2|1<<8)) {
346 wifi_rfkill
= rfkill_alloc("dell-wifi", &platform_device
->dev
,
348 &dell_rfkill_ops
, (void *) 1);
353 ret
= rfkill_register(wifi_rfkill
);
358 if ((status
& (1<<3|1<<9)) == (1<<3|1<<9)) {
359 bluetooth_rfkill
= rfkill_alloc("dell-bluetooth",
360 &platform_device
->dev
,
361 RFKILL_TYPE_BLUETOOTH
,
362 &dell_rfkill_ops
, (void *) 2);
363 if (!bluetooth_rfkill
) {
367 ret
= rfkill_register(bluetooth_rfkill
);
372 if ((status
& (1<<4|1<<10)) == (1<<4|1<<10)) {
373 wwan_rfkill
= rfkill_alloc("dell-wwan",
374 &platform_device
->dev
,
376 &dell_rfkill_ops
, (void *) 3);
381 ret
= rfkill_register(wwan_rfkill
);
388 rfkill_destroy(wwan_rfkill
);
389 if (bluetooth_rfkill
)
390 rfkill_unregister(bluetooth_rfkill
);
392 rfkill_destroy(bluetooth_rfkill
);
394 rfkill_unregister(wifi_rfkill
);
396 rfkill_destroy(wifi_rfkill
);
401 static void dell_cleanup_rfkill(void)
404 rfkill_unregister(wifi_rfkill
);
405 rfkill_destroy(wifi_rfkill
);
407 if (bluetooth_rfkill
) {
408 rfkill_unregister(bluetooth_rfkill
);
409 rfkill_destroy(bluetooth_rfkill
);
412 rfkill_unregister(wwan_rfkill
);
413 rfkill_destroy(wwan_rfkill
);
417 static int dell_send_intensity(struct backlight_device
*bd
)
422 buffer
->input
[0] = find_token_location(BRIGHTNESS_TOKEN
);
423 buffer
->input
[1] = bd
->props
.brightness
;
425 if (buffer
->input
[0] == -1) {
430 if (power_supply_is_system_supplied() > 0)
431 dell_send_request(buffer
, 1, 2);
433 dell_send_request(buffer
, 1, 1);
440 static int dell_get_intensity(struct backlight_device
*bd
)
445 buffer
->input
[0] = find_token_location(BRIGHTNESS_TOKEN
);
447 if (buffer
->input
[0] == -1) {
452 if (power_supply_is_system_supplied() > 0)
453 dell_send_request(buffer
, 0, 2);
455 dell_send_request(buffer
, 0, 1);
461 return buffer
->output
[1];
464 static struct backlight_ops dell_ops
= {
465 .get_brightness
= dell_get_intensity
,
466 .update_status
= dell_send_intensity
,
469 bool dell_laptop_i8042_filter(unsigned char data
, unsigned char str
,
472 static bool extended
;
477 if (unlikely(data
== 0xe0)) {
480 } else if (unlikely(extended
)) {
483 schedule_delayed_work(&dell_rfkill_work
,
484 round_jiffies_relative(HZ
));
493 static int __init
dell_init(void)
495 int max_intensity
= 0;
498 if (!dmi_check_system(dell_device_table
))
501 dmi_walk(find_tokens
, NULL
);
504 printk(KERN_INFO
"dell-laptop: Unable to find dmi tokens\n");
508 ret
= platform_driver_register(&platform_driver
);
510 goto fail_platform_driver
;
511 platform_device
= platform_device_alloc("dell-laptop", -1);
512 if (!platform_device
) {
514 goto fail_platform_device1
;
516 ret
= platform_device_add(platform_device
);
518 goto fail_platform_device2
;
521 * Allocate buffer below 4GB for SMI data--only 32-bit physical addr
522 * is passed to SMI handler.
524 bufferpage
= alloc_page(GFP_KERNEL
| GFP_DMA32
);
528 buffer
= page_address(bufferpage
);
529 mutex_init(&buffer_mutex
);
531 ret
= dell_setup_rfkill();
534 printk(KERN_WARNING
"dell-laptop: Unable to setup rfkill\n");
538 ret
= i8042_install_filter(dell_laptop_i8042_filter
);
541 "dell-laptop: Unable to install key filter\n");
546 /* In the event of an ACPI backlight being available, don't
547 * register the platform controller.
549 if (acpi_video_backlight_support())
554 buffer
->input
[0] = find_token_location(BRIGHTNESS_TOKEN
);
555 if (buffer
->input
[0] != -1) {
556 dell_send_request(buffer
, 0, 2);
557 max_intensity
= buffer
->output
[3];
562 struct backlight_properties props
;
563 memset(&props
, 0, sizeof(struct backlight_properties
));
564 props
.max_brightness
= max_intensity
;
565 dell_backlight_device
= backlight_device_register("dell_backlight",
566 &platform_device
->dev
,
571 if (IS_ERR(dell_backlight_device
)) {
572 ret
= PTR_ERR(dell_backlight_device
);
573 dell_backlight_device
= NULL
;
577 dell_backlight_device
->props
.brightness
=
578 dell_get_intensity(dell_backlight_device
);
579 backlight_update_status(dell_backlight_device
);
585 i8042_remove_filter(dell_laptop_i8042_filter
);
586 cancel_delayed_work_sync(&dell_rfkill_work
);
588 dell_cleanup_rfkill();
590 free_page((unsigned long)bufferpage
);
592 platform_device_del(platform_device
);
593 fail_platform_device2
:
594 platform_device_put(platform_device
);
595 fail_platform_device1
:
596 platform_driver_unregister(&platform_driver
);
597 fail_platform_driver
:
602 static void __exit
dell_exit(void)
604 i8042_remove_filter(dell_laptop_i8042_filter
);
605 cancel_delayed_work_sync(&dell_rfkill_work
);
606 backlight_device_unregister(dell_backlight_device
);
607 dell_cleanup_rfkill();
608 if (platform_device
) {
609 platform_device_unregister(platform_device
);
610 platform_driver_unregister(&platform_driver
);
613 free_page((unsigned long)buffer
);
616 module_init(dell_init
);
617 module_exit(dell_exit
);
619 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
620 MODULE_DESCRIPTION("Dell laptop driver");
621 MODULE_LICENSE("GPL");
622 MODULE_ALIAS("dmi:*svnDellInc.:*:ct8:*");
623 MODULE_ALIAS("dmi:*svnDellComputerCorporation.:*:ct8:*");