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 "../../firmware/dcdbas.h"
27 #define BRIGHTNESS_TOKEN 0x7d
29 /* This structure will be modified by the firmware when we enter
30 * system management mode, hence the volatiles */
32 struct calling_interface_buffer
{
35 volatile u32 input
[4];
36 volatile u32 output
[4];
39 struct calling_interface_token
{
48 struct calling_interface_structure
{
49 struct dmi_header header
;
53 struct calling_interface_token tokens
[];
56 static int da_command_address
;
57 static int da_command_code
;
58 static int da_num_tokens
;
59 static struct calling_interface_token
*da_tokens
;
61 static struct backlight_device
*dell_backlight_device
;
62 static struct rfkill
*wifi_rfkill
;
63 static struct rfkill
*bluetooth_rfkill
;
64 static struct rfkill
*wwan_rfkill
;
66 static const struct dmi_system_id __initdata dell_device_table
[] = {
68 .ident
= "Dell laptop",
70 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
71 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
77 static void parse_da_table(const struct dmi_header
*dm
)
79 /* Final token is a terminator, so we don't want to copy it */
80 int tokens
= (dm
->length
-11)/sizeof(struct calling_interface_token
)-1;
81 struct calling_interface_structure
*table
=
82 container_of(dm
, struct calling_interface_structure
, header
);
84 /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least
90 da_command_address
= table
->cmdIOAddress
;
91 da_command_code
= table
->cmdIOCode
;
93 da_tokens
= krealloc(da_tokens
, (da_num_tokens
+ tokens
) *
94 sizeof(struct calling_interface_token
),
100 memcpy(da_tokens
+da_num_tokens
, table
->tokens
,
101 sizeof(struct calling_interface_token
) * tokens
);
103 da_num_tokens
+= tokens
;
106 static void find_tokens(const struct dmi_header
*dm
, void *dummy
)
109 case 0xd4: /* Indexed IO */
111 case 0xd5: /* Protected Area Type 1 */
113 case 0xd6: /* Protected Area Type 2 */
115 case 0xda: /* Calling interface */
121 static int find_token_location(int tokenid
)
124 for (i
= 0; i
< da_num_tokens
; i
++) {
125 if (da_tokens
[i
].tokenID
== tokenid
)
126 return da_tokens
[i
].location
;
132 static struct calling_interface_buffer
*
133 dell_send_request(struct calling_interface_buffer
*buffer
, int class,
136 struct smi_cmd command
;
138 command
.magic
= SMI_CMD_MAGIC
;
139 command
.command_address
= da_command_address
;
140 command
.command_code
= da_command_code
;
141 command
.ebx
= virt_to_phys(buffer
);
142 command
.ecx
= 0x42534931;
144 buffer
->class = class;
145 buffer
->select
= select
;
147 dcdbas_smi_request(&command
);
152 /* Derived from information in DellWirelessCtl.cpp:
153 Class 17, select 11 is radio control. It returns an array of 32-bit values.
155 result[0]: return code
157 Bit 0: Hardware switch supported
158 Bit 1: Wifi locator supported
159 Bit 2: Wifi is supported
160 Bit 3: Bluetooth is supported
161 Bit 4: WWAN is supported
162 Bit 5: Wireless keyboard supported
164 Bit 8: Wifi is installed
165 Bit 9: Bluetooth is installed
166 Bit 10: WWAN is installed
168 Bit 16: Hardware switch is on
169 Bit 17: Wifi is blocked
170 Bit 18: Bluetooth is blocked
171 Bit 19: WWAN is blocked
173 result[2]: NVRAM size in bytes
174 result[3]: NVRAM format version number
177 static int dell_rfkill_set(void *data
, bool blocked
)
179 struct calling_interface_buffer buffer
;
180 int disable
= blocked
? 1 : 0;
181 unsigned long radio
= (unsigned long)data
;
183 memset(&buffer
, 0, sizeof(struct calling_interface_buffer
));
184 buffer
.input
[0] = (1 | (radio
<<8) | (disable
<< 16));
185 dell_send_request(&buffer
, 17, 11);
190 static void dell_rfkill_query(struct rfkill
*rfkill
, void *data
)
192 struct calling_interface_buffer buffer
;
194 int bit
= (unsigned long)data
+ 16;
196 memset(&buffer
, 0, sizeof(struct calling_interface_buffer
));
197 dell_send_request(&buffer
, 17, 11);
198 status
= buffer
.output
[1];
200 if (status
& BIT(bit
))
201 rfkill_set_hw_state(rfkill
, !!(status
& BIT(16)));
204 static const struct rfkill_ops dell_rfkill_ops
= {
205 .set_block
= dell_rfkill_set
,
206 .query
= dell_rfkill_query
,
209 static int dell_setup_rfkill(void)
211 struct calling_interface_buffer buffer
;
215 memset(&buffer
, 0, sizeof(struct calling_interface_buffer
));
216 dell_send_request(&buffer
, 17, 11);
217 status
= buffer
.output
[1];
219 if ((status
& (1<<2|1<<8)) == (1<<2|1<<8)) {
220 wifi_rfkill
= rfkill_alloc("dell-wifi", NULL
, RFKILL_TYPE_WLAN
,
221 &dell_rfkill_ops
, (void *) 1);
226 ret
= rfkill_register(wifi_rfkill
);
231 if ((status
& (1<<3|1<<9)) == (1<<3|1<<9)) {
232 bluetooth_rfkill
= rfkill_alloc("dell-bluetooth", NULL
,
233 RFKILL_TYPE_BLUETOOTH
,
234 &dell_rfkill_ops
, (void *) 2);
235 if (!bluetooth_rfkill
) {
239 ret
= rfkill_register(bluetooth_rfkill
);
244 if ((status
& (1<<4|1<<10)) == (1<<4|1<<10)) {
245 wwan_rfkill
= rfkill_alloc("dell-wwan", NULL
, RFKILL_TYPE_WWAN
,
246 &dell_rfkill_ops
, (void *) 3);
251 ret
= rfkill_register(wwan_rfkill
);
258 rfkill_destroy(wwan_rfkill
);
259 if (bluetooth_rfkill
)
260 rfkill_unregister(bluetooth_rfkill
);
262 rfkill_destroy(bluetooth_rfkill
);
264 rfkill_unregister(wifi_rfkill
);
266 rfkill_destroy(wifi_rfkill
);
271 static int dell_send_intensity(struct backlight_device
*bd
)
273 struct calling_interface_buffer buffer
;
275 memset(&buffer
, 0, sizeof(struct calling_interface_buffer
));
276 buffer
.input
[0] = find_token_location(BRIGHTNESS_TOKEN
);
277 buffer
.input
[1] = bd
->props
.brightness
;
279 if (buffer
.input
[0] == -1)
282 if (power_supply_is_system_supplied() > 0)
283 dell_send_request(&buffer
, 1, 2);
285 dell_send_request(&buffer
, 1, 1);
290 static int dell_get_intensity(struct backlight_device
*bd
)
292 struct calling_interface_buffer buffer
;
294 memset(&buffer
, 0, sizeof(struct calling_interface_buffer
));
295 buffer
.input
[0] = find_token_location(BRIGHTNESS_TOKEN
);
297 if (buffer
.input
[0] == -1)
300 if (power_supply_is_system_supplied() > 0)
301 dell_send_request(&buffer
, 0, 2);
303 dell_send_request(&buffer
, 0, 1);
305 return buffer
.output
[1];
308 static struct backlight_ops dell_ops
= {
309 .get_brightness
= dell_get_intensity
,
310 .update_status
= dell_send_intensity
,
313 static int __init
dell_init(void)
315 struct calling_interface_buffer buffer
;
316 int max_intensity
= 0;
319 if (!dmi_check_system(dell_device_table
))
322 dmi_walk(find_tokens
, NULL
);
325 printk(KERN_INFO
"dell-laptop: Unable to find dmi tokens\n");
329 ret
= dell_setup_rfkill();
332 printk(KERN_WARNING
"dell-laptop: Unable to setup rfkill\n");
337 /* In the event of an ACPI backlight being available, don't
338 * register the platform controller.
340 if (acpi_video_backlight_support())
344 memset(&buffer
, 0, sizeof(struct calling_interface_buffer
));
345 buffer
.input
[0] = find_token_location(BRIGHTNESS_TOKEN
);
347 if (buffer
.input
[0] != -1) {
348 dell_send_request(&buffer
, 0, 2);
349 max_intensity
= buffer
.output
[3];
353 dell_backlight_device
= backlight_device_register(
358 if (IS_ERR(dell_backlight_device
)) {
359 ret
= PTR_ERR(dell_backlight_device
);
360 dell_backlight_device
= NULL
;
364 dell_backlight_device
->props
.max_brightness
= max_intensity
;
365 dell_backlight_device
->props
.brightness
=
366 dell_get_intensity(dell_backlight_device
);
367 backlight_update_status(dell_backlight_device
);
373 rfkill_unregister(wifi_rfkill
);
374 if (bluetooth_rfkill
)
375 rfkill_unregister(bluetooth_rfkill
);
377 rfkill_unregister(wwan_rfkill
);
382 static void __exit
dell_exit(void)
384 backlight_device_unregister(dell_backlight_device
);
386 rfkill_unregister(wifi_rfkill
);
387 if (bluetooth_rfkill
)
388 rfkill_unregister(bluetooth_rfkill
);
390 rfkill_unregister(wwan_rfkill
);
393 module_init(dell_init
);
394 module_exit(dell_exit
);
396 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
397 MODULE_DESCRIPTION("Dell laptop driver");
398 MODULE_LICENSE("GPL");
399 MODULE_ALIAS("dmi:*svnDellInc.:*:ct8:*");