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>
25 #include <linux/i8042.h>
26 #include "../../firmware/dcdbas.h"
28 #define BRIGHTNESS_TOKEN 0x7d
30 /* This structure will be modified by the firmware when we enter
31 * system management mode, hence the volatiles */
33 struct calling_interface_buffer
{
36 volatile u32 input
[4];
37 volatile u32 output
[4];
40 struct calling_interface_token
{
49 struct calling_interface_structure
{
50 struct dmi_header header
;
54 struct calling_interface_token tokens
[];
57 static int da_command_address
;
58 static int da_command_code
;
59 static int da_num_tokens
;
60 static struct calling_interface_token
*da_tokens
;
62 static struct platform_driver platform_driver
= {
64 .name
= "dell-laptop",
69 static struct platform_device
*platform_device
;
70 static struct backlight_device
*dell_backlight_device
;
71 static struct rfkill
*wifi_rfkill
;
72 static struct rfkill
*bluetooth_rfkill
;
73 static struct rfkill
*wwan_rfkill
;
75 static const struct dmi_system_id __initdata dell_device_table
[] = {
77 .ident
= "Dell laptop",
79 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
80 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
86 static void __init
parse_da_table(const struct dmi_header
*dm
)
88 /* Final token is a terminator, so we don't want to copy it */
89 int tokens
= (dm
->length
-11)/sizeof(struct calling_interface_token
)-1;
90 struct calling_interface_structure
*table
=
91 container_of(dm
, struct calling_interface_structure
, header
);
93 /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least
99 da_command_address
= table
->cmdIOAddress
;
100 da_command_code
= table
->cmdIOCode
;
102 da_tokens
= krealloc(da_tokens
, (da_num_tokens
+ tokens
) *
103 sizeof(struct calling_interface_token
),
109 memcpy(da_tokens
+da_num_tokens
, table
->tokens
,
110 sizeof(struct calling_interface_token
) * tokens
);
112 da_num_tokens
+= tokens
;
115 static void __init
find_tokens(const struct dmi_header
*dm
, void *dummy
)
118 case 0xd4: /* Indexed IO */
120 case 0xd5: /* Protected Area Type 1 */
122 case 0xd6: /* Protected Area Type 2 */
124 case 0xda: /* Calling interface */
130 static int find_token_location(int tokenid
)
133 for (i
= 0; i
< da_num_tokens
; i
++) {
134 if (da_tokens
[i
].tokenID
== tokenid
)
135 return da_tokens
[i
].location
;
141 static struct calling_interface_buffer
*
142 dell_send_request(struct calling_interface_buffer
*buffer
, int class,
145 struct smi_cmd command
;
147 command
.magic
= SMI_CMD_MAGIC
;
148 command
.command_address
= da_command_address
;
149 command
.command_code
= da_command_code
;
150 command
.ebx
= virt_to_phys(buffer
);
151 command
.ecx
= 0x42534931;
153 buffer
->class = class;
154 buffer
->select
= select
;
156 dcdbas_smi_request(&command
);
161 /* Derived from information in DellWirelessCtl.cpp:
162 Class 17, select 11 is radio control. It returns an array of 32-bit values.
164 result[0]: return code
166 Bit 0: Hardware switch supported
167 Bit 1: Wifi locator supported
168 Bit 2: Wifi is supported
169 Bit 3: Bluetooth is supported
170 Bit 4: WWAN is supported
171 Bit 5: Wireless keyboard supported
173 Bit 8: Wifi is installed
174 Bit 9: Bluetooth is installed
175 Bit 10: WWAN is installed
177 Bit 16: Hardware switch is on
178 Bit 17: Wifi is blocked
179 Bit 18: Bluetooth is blocked
180 Bit 19: WWAN is blocked
182 result[2]: NVRAM size in bytes
183 result[3]: NVRAM format version number
186 static int dell_rfkill_set(void *data
, bool blocked
)
188 struct calling_interface_buffer buffer
;
189 int disable
= blocked
? 1 : 0;
190 unsigned long radio
= (unsigned long)data
;
192 memset(&buffer
, 0, sizeof(struct calling_interface_buffer
));
193 dell_send_request(&buffer
, 17, 11);
194 if (!(buffer
.output
[1] & BIT(16)))
197 buffer
.input
[0] = (1 | (radio
<<8) | (disable
<< 16));
198 dell_send_request(&buffer
, 17, 11);
203 static void dell_rfkill_query(struct rfkill
*rfkill
, void *data
)
205 struct calling_interface_buffer buffer
;
207 int bit
= (unsigned long)data
+ 16;
209 memset(&buffer
, 0, sizeof(struct calling_interface_buffer
));
210 dell_send_request(&buffer
, 17, 11);
211 status
= buffer
.output
[1];
213 rfkill_set_sw_state(rfkill
, !!(status
& BIT(bit
)));
214 rfkill_set_hw_state(rfkill
, !(status
& BIT(16)));
217 static const struct rfkill_ops dell_rfkill_ops
= {
218 .set_block
= dell_rfkill_set
,
219 .query
= dell_rfkill_query
,
222 static void dell_update_rfkill(struct work_struct
*ignored
)
225 dell_rfkill_query(wifi_rfkill
, (void *)1);
226 if (bluetooth_rfkill
)
227 dell_rfkill_query(bluetooth_rfkill
, (void *)2);
229 dell_rfkill_query(wwan_rfkill
, (void *)3);
231 static DECLARE_DELAYED_WORK(dell_rfkill_work
, dell_update_rfkill
);
234 static int __init
dell_setup_rfkill(void)
236 struct calling_interface_buffer buffer
;
240 memset(&buffer
, 0, sizeof(struct calling_interface_buffer
));
241 dell_send_request(&buffer
, 17, 11);
242 status
= buffer
.output
[1];
244 if ((status
& (1<<2|1<<8)) == (1<<2|1<<8)) {
245 wifi_rfkill
= rfkill_alloc("dell-wifi", &platform_device
->dev
,
247 &dell_rfkill_ops
, (void *) 1);
252 ret
= rfkill_register(wifi_rfkill
);
257 if ((status
& (1<<3|1<<9)) == (1<<3|1<<9)) {
258 bluetooth_rfkill
= rfkill_alloc("dell-bluetooth",
259 &platform_device
->dev
,
260 RFKILL_TYPE_BLUETOOTH
,
261 &dell_rfkill_ops
, (void *) 2);
262 if (!bluetooth_rfkill
) {
266 ret
= rfkill_register(bluetooth_rfkill
);
271 if ((status
& (1<<4|1<<10)) == (1<<4|1<<10)) {
272 wwan_rfkill
= rfkill_alloc("dell-wwan",
273 &platform_device
->dev
,
275 &dell_rfkill_ops
, (void *) 3);
280 ret
= rfkill_register(wwan_rfkill
);
287 rfkill_destroy(wwan_rfkill
);
288 if (bluetooth_rfkill
)
289 rfkill_unregister(bluetooth_rfkill
);
291 rfkill_destroy(bluetooth_rfkill
);
293 rfkill_unregister(wifi_rfkill
);
295 rfkill_destroy(wifi_rfkill
);
300 static void dell_cleanup_rfkill(void)
303 rfkill_unregister(wifi_rfkill
);
304 rfkill_destroy(wifi_rfkill
);
306 if (bluetooth_rfkill
) {
307 rfkill_unregister(bluetooth_rfkill
);
308 rfkill_destroy(bluetooth_rfkill
);
311 rfkill_unregister(wwan_rfkill
);
312 rfkill_destroy(wwan_rfkill
);
316 static int dell_send_intensity(struct backlight_device
*bd
)
318 struct calling_interface_buffer buffer
;
320 memset(&buffer
, 0, sizeof(struct calling_interface_buffer
));
321 buffer
.input
[0] = find_token_location(BRIGHTNESS_TOKEN
);
322 buffer
.input
[1] = bd
->props
.brightness
;
324 if (buffer
.input
[0] == -1)
327 if (power_supply_is_system_supplied() > 0)
328 dell_send_request(&buffer
, 1, 2);
330 dell_send_request(&buffer
, 1, 1);
335 static int dell_get_intensity(struct backlight_device
*bd
)
337 struct calling_interface_buffer buffer
;
339 memset(&buffer
, 0, sizeof(struct calling_interface_buffer
));
340 buffer
.input
[0] = find_token_location(BRIGHTNESS_TOKEN
);
342 if (buffer
.input
[0] == -1)
345 if (power_supply_is_system_supplied() > 0)
346 dell_send_request(&buffer
, 0, 2);
348 dell_send_request(&buffer
, 0, 1);
350 return buffer
.output
[1];
353 static struct backlight_ops dell_ops
= {
354 .get_brightness
= dell_get_intensity
,
355 .update_status
= dell_send_intensity
,
358 bool dell_laptop_i8042_filter(unsigned char data
, unsigned char str
,
361 static bool extended
;
366 if (unlikely(data
== 0xe0)) {
369 } else if (unlikely(extended
)) {
372 schedule_delayed_work(&dell_rfkill_work
,
373 round_jiffies_relative(HZ
));
382 static int __init
dell_init(void)
384 struct calling_interface_buffer buffer
;
385 int max_intensity
= 0;
388 if (!dmi_check_system(dell_device_table
))
391 dmi_walk(find_tokens
, NULL
);
394 printk(KERN_INFO
"dell-laptop: Unable to find dmi tokens\n");
398 ret
= platform_driver_register(&platform_driver
);
400 goto fail_platform_driver
;
401 platform_device
= platform_device_alloc("dell-laptop", -1);
402 if (!platform_device
) {
404 goto fail_platform_device1
;
406 ret
= platform_device_add(platform_device
);
408 goto fail_platform_device2
;
410 ret
= dell_setup_rfkill();
413 printk(KERN_WARNING
"dell-laptop: Unable to setup rfkill\n");
417 ret
= i8042_install_filter(dell_laptop_i8042_filter
);
420 "dell-laptop: Unable to install key filter\n");
425 /* In the event of an ACPI backlight being available, don't
426 * register the platform controller.
428 if (acpi_video_backlight_support())
432 memset(&buffer
, 0, sizeof(struct calling_interface_buffer
));
433 buffer
.input
[0] = find_token_location(BRIGHTNESS_TOKEN
);
435 if (buffer
.input
[0] != -1) {
436 dell_send_request(&buffer
, 0, 2);
437 max_intensity
= buffer
.output
[3];
441 dell_backlight_device
= backlight_device_register(
443 &platform_device
->dev
, NULL
,
446 if (IS_ERR(dell_backlight_device
)) {
447 ret
= PTR_ERR(dell_backlight_device
);
448 dell_backlight_device
= NULL
;
452 dell_backlight_device
->props
.max_brightness
= max_intensity
;
453 dell_backlight_device
->props
.brightness
=
454 dell_get_intensity(dell_backlight_device
);
455 backlight_update_status(dell_backlight_device
);
461 i8042_remove_filter(dell_laptop_i8042_filter
);
463 dell_cleanup_rfkill();
465 platform_device_del(platform_device
);
466 fail_platform_device2
:
467 platform_device_put(platform_device
);
468 fail_platform_device1
:
469 platform_driver_unregister(&platform_driver
);
470 fail_platform_driver
:
475 static void __exit
dell_exit(void)
477 cancel_delayed_work_sync(&dell_rfkill_work
);
478 i8042_remove_filter(dell_laptop_i8042_filter
);
479 backlight_device_unregister(dell_backlight_device
);
480 dell_cleanup_rfkill();
481 if (platform_device
) {
482 platform_device_del(platform_device
);
483 platform_driver_unregister(&platform_driver
);
488 module_init(dell_init
);
489 module_exit(dell_exit
);
491 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
492 MODULE_DESCRIPTION("Dell laptop driver");
493 MODULE_LICENSE("GPL");
494 MODULE_ALIAS("dmi:*svnDellInc.:*:ct8:*");