2009-01-08 10:08:56 +08:00
|
|
|
/*
|
|
|
|
* Driver for Dell laptop extras
|
|
|
|
*
|
|
|
|
* Copyright (c) Red Hat <mjg@redhat.com>
|
|
|
|
*
|
|
|
|
* Based on documentation in the libsmbios package, Copyright (C) 2005 Dell
|
|
|
|
* Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/backlight.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/dmi.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/rfkill.h>
|
|
|
|
#include <linux/power_supply.h>
|
|
|
|
#include <linux/acpi.h>
|
2010-02-11 03:12:13 +08:00
|
|
|
#include <linux/mm.h>
|
2009-12-10 02:23:36 +08:00
|
|
|
#include <linux/i8042.h>
|
2009-01-10 06:23:38 +08:00
|
|
|
#include "../../firmware/dcdbas.h"
|
2009-01-08 10:08:56 +08:00
|
|
|
|
|
|
|
#define BRIGHTNESS_TOKEN 0x7d
|
|
|
|
|
|
|
|
/* This structure will be modified by the firmware when we enter
|
|
|
|
* system management mode, hence the volatiles */
|
|
|
|
|
|
|
|
struct calling_interface_buffer {
|
|
|
|
u16 class;
|
|
|
|
u16 select;
|
|
|
|
volatile u32 input[4];
|
|
|
|
volatile u32 output[4];
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
struct calling_interface_token {
|
|
|
|
u16 tokenID;
|
|
|
|
u16 location;
|
|
|
|
union {
|
|
|
|
u16 value;
|
|
|
|
u16 stringlength;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct calling_interface_structure {
|
|
|
|
struct dmi_header header;
|
|
|
|
u16 cmdIOAddress;
|
|
|
|
u8 cmdIOCode;
|
|
|
|
u32 supportedCmds;
|
|
|
|
struct calling_interface_token tokens[];
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
static int da_command_address;
|
|
|
|
static int da_command_code;
|
|
|
|
static int da_num_tokens;
|
|
|
|
static struct calling_interface_token *da_tokens;
|
|
|
|
|
2009-08-19 22:06:49 +08:00
|
|
|
static struct platform_driver platform_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "dell-laptop",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_device *platform_device;
|
2009-01-08 10:08:56 +08:00
|
|
|
static struct backlight_device *dell_backlight_device;
|
|
|
|
static struct rfkill *wifi_rfkill;
|
|
|
|
static struct rfkill *bluetooth_rfkill;
|
|
|
|
static struct rfkill *wwan_rfkill;
|
|
|
|
|
|
|
|
static const struct dmi_system_id __initdata dell_device_table[] = {
|
|
|
|
{
|
|
|
|
.ident = "Dell laptop",
|
|
|
|
.matches = {
|
|
|
|
DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
|
|
|
|
DMI_MATCH(DMI_CHASSIS_TYPE, "8"),
|
|
|
|
},
|
|
|
|
},
|
2010-02-15 00:53:23 +08:00
|
|
|
{
|
|
|
|
.ident = "Dell Computer Corporation",
|
|
|
|
.matches = {
|
|
|
|
DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
|
|
|
|
DMI_MATCH(DMI_CHASSIS_TYPE, "8"),
|
|
|
|
},
|
|
|
|
},
|
2009-01-08 10:08:56 +08:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2010-02-10 06:41:03 +08:00
|
|
|
static struct dmi_system_id __devinitdata dell_blacklist[] = {
|
|
|
|
/* Supported by compal-laptop */
|
|
|
|
{
|
|
|
|
.ident = "Dell Mini 9",
|
|
|
|
.matches = {
|
|
|
|
DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
|
|
|
|
DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 910"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.ident = "Dell Mini 10",
|
|
|
|
.matches = {
|
|
|
|
DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
|
|
|
|
DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1010"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.ident = "Dell Mini 10v",
|
|
|
|
.matches = {
|
|
|
|
DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
|
|
|
|
DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1011"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.ident = "Dell Inspiron 11z",
|
|
|
|
.matches = {
|
|
|
|
DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
|
|
|
|
DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1110"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.ident = "Dell Mini 12",
|
|
|
|
.matches = {
|
|
|
|
DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
|
|
|
|
DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1210"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2010-02-11 03:12:13 +08:00
|
|
|
static struct calling_interface_buffer *buffer;
|
2010-03-01 22:43:52 +08:00
|
|
|
static struct page *bufferpage;
|
|
|
|
static DEFINE_MUTEX(buffer_mutex);
|
2010-02-11 03:12:13 +08:00
|
|
|
|
2010-02-11 03:44:03 +08:00
|
|
|
static int hwswitch_state;
|
|
|
|
|
2010-02-11 03:12:13 +08:00
|
|
|
static void get_buffer(void)
|
|
|
|
{
|
|
|
|
mutex_lock(&buffer_mutex);
|
|
|
|
memset(buffer, 0, sizeof(struct calling_interface_buffer));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void release_buffer(void)
|
|
|
|
{
|
|
|
|
mutex_unlock(&buffer_mutex);
|
|
|
|
}
|
|
|
|
|
2009-08-19 22:06:50 +08:00
|
|
|
static void __init parse_da_table(const struct dmi_header *dm)
|
2009-01-08 10:08:56 +08:00
|
|
|
{
|
|
|
|
/* Final token is a terminator, so we don't want to copy it */
|
|
|
|
int tokens = (dm->length-11)/sizeof(struct calling_interface_token)-1;
|
|
|
|
struct calling_interface_structure *table =
|
|
|
|
container_of(dm, struct calling_interface_structure, header);
|
|
|
|
|
|
|
|
/* 4 bytes of table header, plus 7 bytes of Dell header, plus at least
|
|
|
|
6 bytes of entry */
|
|
|
|
|
|
|
|
if (dm->length < 17)
|
|
|
|
return;
|
|
|
|
|
|
|
|
da_command_address = table->cmdIOAddress;
|
|
|
|
da_command_code = table->cmdIOCode;
|
|
|
|
|
|
|
|
da_tokens = krealloc(da_tokens, (da_num_tokens + tokens) *
|
|
|
|
sizeof(struct calling_interface_token),
|
|
|
|
GFP_KERNEL);
|
|
|
|
|
|
|
|
if (!da_tokens)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memcpy(da_tokens+da_num_tokens, table->tokens,
|
|
|
|
sizeof(struct calling_interface_token) * tokens);
|
|
|
|
|
|
|
|
da_num_tokens += tokens;
|
|
|
|
}
|
|
|
|
|
2009-08-19 22:06:50 +08:00
|
|
|
static void __init find_tokens(const struct dmi_header *dm, void *dummy)
|
2009-01-08 10:08:56 +08:00
|
|
|
{
|
|
|
|
switch (dm->type) {
|
|
|
|
case 0xd4: /* Indexed IO */
|
|
|
|
break;
|
|
|
|
case 0xd5: /* Protected Area Type 1 */
|
|
|
|
break;
|
|
|
|
case 0xd6: /* Protected Area Type 2 */
|
|
|
|
break;
|
|
|
|
case 0xda: /* Calling interface */
|
|
|
|
parse_da_table(dm);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int find_token_location(int tokenid)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < da_num_tokens; i++) {
|
|
|
|
if (da_tokens[i].tokenID == tokenid)
|
|
|
|
return da_tokens[i].location;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct calling_interface_buffer *
|
|
|
|
dell_send_request(struct calling_interface_buffer *buffer, int class,
|
|
|
|
int select)
|
|
|
|
{
|
|
|
|
struct smi_cmd command;
|
|
|
|
|
|
|
|
command.magic = SMI_CMD_MAGIC;
|
|
|
|
command.command_address = da_command_address;
|
|
|
|
command.command_code = da_command_code;
|
|
|
|
command.ebx = virt_to_phys(buffer);
|
|
|
|
command.ecx = 0x42534931;
|
|
|
|
|
|
|
|
buffer->class = class;
|
|
|
|
buffer->select = select;
|
|
|
|
|
|
|
|
dcdbas_smi_request(&command);
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Derived from information in DellWirelessCtl.cpp:
|
|
|
|
Class 17, select 11 is radio control. It returns an array of 32-bit values.
|
|
|
|
|
2010-02-11 03:44:03 +08:00
|
|
|
Input byte 0 = 0: Wireless information
|
|
|
|
|
2009-01-08 10:08:56 +08:00
|
|
|
result[0]: return code
|
|
|
|
result[1]:
|
|
|
|
Bit 0: Hardware switch supported
|
|
|
|
Bit 1: Wifi locator supported
|
|
|
|
Bit 2: Wifi is supported
|
|
|
|
Bit 3: Bluetooth is supported
|
|
|
|
Bit 4: WWAN is supported
|
|
|
|
Bit 5: Wireless keyboard supported
|
|
|
|
Bits 6-7: Reserved
|
|
|
|
Bit 8: Wifi is installed
|
|
|
|
Bit 9: Bluetooth is installed
|
|
|
|
Bit 10: WWAN is installed
|
|
|
|
Bits 11-15: Reserved
|
|
|
|
Bit 16: Hardware switch is on
|
|
|
|
Bit 17: Wifi is blocked
|
|
|
|
Bit 18: Bluetooth is blocked
|
|
|
|
Bit 19: WWAN is blocked
|
|
|
|
Bits 20-31: Reserved
|
|
|
|
result[2]: NVRAM size in bytes
|
|
|
|
result[3]: NVRAM format version number
|
2010-02-11 03:44:03 +08:00
|
|
|
|
|
|
|
Input byte 0 = 2: Wireless switch configuration
|
|
|
|
result[0]: return code
|
|
|
|
result[1]:
|
|
|
|
Bit 0: Wifi controlled by switch
|
|
|
|
Bit 1: Bluetooth controlled by switch
|
|
|
|
Bit 2: WWAN controlled by switch
|
|
|
|
Bits 3-6: Reserved
|
|
|
|
Bit 7: Wireless switch config locked
|
|
|
|
Bit 8: Wifi locator enabled
|
|
|
|
Bits 9-14: Reserved
|
|
|
|
Bit 15: Wifi locator setting locked
|
|
|
|
Bits 16-31: Reserved
|
2009-01-08 10:08:56 +08:00
|
|
|
*/
|
|
|
|
|
2009-06-02 19:01:37 +08:00
|
|
|
static int dell_rfkill_set(void *data, bool blocked)
|
2009-01-08 10:08:56 +08:00
|
|
|
{
|
2009-06-15 22:26:47 +08:00
|
|
|
int disable = blocked ? 1 : 0;
|
2009-06-02 19:01:37 +08:00
|
|
|
unsigned long radio = (unsigned long)data;
|
2010-02-11 03:44:03 +08:00
|
|
|
int hwswitch_bit = (unsigned long)data - 1;
|
2010-02-11 03:12:13 +08:00
|
|
|
int ret = 0;
|
2009-01-08 10:08:56 +08:00
|
|
|
|
2010-02-11 03:12:13 +08:00
|
|
|
get_buffer();
|
|
|
|
dell_send_request(buffer, 17, 11);
|
2010-02-10 03:11:05 +08:00
|
|
|
|
2010-02-11 03:44:03 +08:00
|
|
|
/* If the hardware switch controls this radio, and the hardware
|
|
|
|
switch is disabled, don't allow changing the software state */
|
|
|
|
if ((hwswitch_state & BIT(hwswitch_bit)) &&
|
|
|
|
!(buffer->output[1] & BIT(16))) {
|
2010-02-11 03:12:13 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-01-08 10:08:56 +08:00
|
|
|
|
2010-02-11 03:12:13 +08:00
|
|
|
buffer->input[0] = (1 | (radio<<8) | (disable << 16));
|
|
|
|
dell_send_request(buffer, 17, 11);
|
|
|
|
|
|
|
|
out:
|
|
|
|
release_buffer();
|
|
|
|
return ret;
|
2009-01-08 10:08:56 +08:00
|
|
|
}
|
|
|
|
|
2009-06-02 19:01:37 +08:00
|
|
|
static void dell_rfkill_query(struct rfkill *rfkill, void *data)
|
2009-01-08 10:08:56 +08:00
|
|
|
{
|
|
|
|
int status;
|
2009-06-02 19:01:37 +08:00
|
|
|
int bit = (unsigned long)data + 16;
|
2010-02-11 03:44:03 +08:00
|
|
|
int hwswitch_bit = (unsigned long)data - 1;
|
2009-01-08 10:08:56 +08:00
|
|
|
|
2010-02-11 03:12:13 +08:00
|
|
|
get_buffer();
|
|
|
|
dell_send_request(buffer, 17, 11);
|
|
|
|
status = buffer->output[1];
|
|
|
|
release_buffer();
|
2009-01-08 10:08:56 +08:00
|
|
|
|
2009-07-31 10:25:38 +08:00
|
|
|
rfkill_set_sw_state(rfkill, !!(status & BIT(bit)));
|
2010-02-11 03:44:03 +08:00
|
|
|
|
|
|
|
if (hwswitch_state & (BIT(hwswitch_bit)))
|
|
|
|
rfkill_set_hw_state(rfkill, !(status & BIT(16)));
|
2009-01-08 10:08:56 +08:00
|
|
|
}
|
|
|
|
|
2009-06-02 19:01:37 +08:00
|
|
|
static const struct rfkill_ops dell_rfkill_ops = {
|
|
|
|
.set_block = dell_rfkill_set,
|
|
|
|
.query = dell_rfkill_query,
|
|
|
|
};
|
2009-01-08 10:08:56 +08:00
|
|
|
|
2009-12-10 02:23:36 +08:00
|
|
|
static void dell_update_rfkill(struct work_struct *ignored)
|
|
|
|
{
|
|
|
|
if (wifi_rfkill)
|
|
|
|
dell_rfkill_query(wifi_rfkill, (void *)1);
|
|
|
|
if (bluetooth_rfkill)
|
|
|
|
dell_rfkill_query(bluetooth_rfkill, (void *)2);
|
|
|
|
if (wwan_rfkill)
|
|
|
|
dell_rfkill_query(wwan_rfkill, (void *)3);
|
|
|
|
}
|
|
|
|
static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill);
|
|
|
|
|
|
|
|
|
2009-08-19 22:06:50 +08:00
|
|
|
static int __init dell_setup_rfkill(void)
|
2009-01-08 10:08:56 +08:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
int ret;
|
|
|
|
|
2010-02-10 06:41:03 +08:00
|
|
|
if (dmi_check_system(dell_blacklist)) {
|
|
|
|
printk(KERN_INFO "dell-laptop: Blacklisted hardware detected - "
|
|
|
|
"not enabling rfkill\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-11 03:12:13 +08:00
|
|
|
get_buffer();
|
|
|
|
dell_send_request(buffer, 17, 11);
|
|
|
|
status = buffer->output[1];
|
2010-02-11 03:44:03 +08:00
|
|
|
buffer->input[0] = 0x2;
|
|
|
|
dell_send_request(buffer, 17, 11);
|
|
|
|
hwswitch_state = buffer->output[1];
|
2010-02-11 03:12:13 +08:00
|
|
|
release_buffer();
|
2009-01-08 10:08:56 +08:00
|
|
|
|
|
|
|
if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) {
|
2009-08-19 22:06:49 +08:00
|
|
|
wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev,
|
|
|
|
RFKILL_TYPE_WLAN,
|
2009-06-02 19:01:37 +08:00
|
|
|
&dell_rfkill_ops, (void *) 1);
|
|
|
|
if (!wifi_rfkill) {
|
|
|
|
ret = -ENOMEM;
|
2009-01-08 10:08:56 +08:00
|
|
|
goto err_wifi;
|
2009-06-02 19:01:37 +08:00
|
|
|
}
|
2009-01-08 10:08:56 +08:00
|
|
|
ret = rfkill_register(wifi_rfkill);
|
|
|
|
if (ret)
|
|
|
|
goto err_wifi;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((status & (1<<3|1<<9)) == (1<<3|1<<9)) {
|
2009-08-19 22:06:49 +08:00
|
|
|
bluetooth_rfkill = rfkill_alloc("dell-bluetooth",
|
|
|
|
&platform_device->dev,
|
2009-06-02 19:01:37 +08:00
|
|
|
RFKILL_TYPE_BLUETOOTH,
|
|
|
|
&dell_rfkill_ops, (void *) 2);
|
|
|
|
if (!bluetooth_rfkill) {
|
|
|
|
ret = -ENOMEM;
|
2009-01-08 10:08:56 +08:00
|
|
|
goto err_bluetooth;
|
2009-06-02 19:01:37 +08:00
|
|
|
}
|
2009-01-08 10:08:56 +08:00
|
|
|
ret = rfkill_register(bluetooth_rfkill);
|
|
|
|
if (ret)
|
|
|
|
goto err_bluetooth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((status & (1<<4|1<<10)) == (1<<4|1<<10)) {
|
2009-08-19 22:06:49 +08:00
|
|
|
wwan_rfkill = rfkill_alloc("dell-wwan",
|
|
|
|
&platform_device->dev,
|
|
|
|
RFKILL_TYPE_WWAN,
|
2009-06-02 19:01:37 +08:00
|
|
|
&dell_rfkill_ops, (void *) 3);
|
|
|
|
if (!wwan_rfkill) {
|
|
|
|
ret = -ENOMEM;
|
2009-01-08 10:08:56 +08:00
|
|
|
goto err_wwan;
|
2009-06-02 19:01:37 +08:00
|
|
|
}
|
2009-01-08 10:08:56 +08:00
|
|
|
ret = rfkill_register(wwan_rfkill);
|
|
|
|
if (ret)
|
|
|
|
goto err_wwan;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
err_wwan:
|
2009-06-02 19:01:37 +08:00
|
|
|
rfkill_destroy(wwan_rfkill);
|
|
|
|
if (bluetooth_rfkill)
|
2009-01-08 10:08:56 +08:00
|
|
|
rfkill_unregister(bluetooth_rfkill);
|
|
|
|
err_bluetooth:
|
2009-06-02 19:01:37 +08:00
|
|
|
rfkill_destroy(bluetooth_rfkill);
|
|
|
|
if (wifi_rfkill)
|
2009-01-08 10:08:56 +08:00
|
|
|
rfkill_unregister(wifi_rfkill);
|
|
|
|
err_wifi:
|
2009-06-02 19:01:37 +08:00
|
|
|
rfkill_destroy(wifi_rfkill);
|
2009-01-08 10:08:56 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-08-19 22:06:48 +08:00
|
|
|
static void dell_cleanup_rfkill(void)
|
|
|
|
{
|
|
|
|
if (wifi_rfkill) {
|
|
|
|
rfkill_unregister(wifi_rfkill);
|
|
|
|
rfkill_destroy(wifi_rfkill);
|
|
|
|
}
|
|
|
|
if (bluetooth_rfkill) {
|
|
|
|
rfkill_unregister(bluetooth_rfkill);
|
|
|
|
rfkill_destroy(bluetooth_rfkill);
|
|
|
|
}
|
|
|
|
if (wwan_rfkill) {
|
|
|
|
rfkill_unregister(wwan_rfkill);
|
|
|
|
rfkill_destroy(wwan_rfkill);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-08 10:08:56 +08:00
|
|
|
static int dell_send_intensity(struct backlight_device *bd)
|
|
|
|
{
|
2010-02-11 03:12:13 +08:00
|
|
|
int ret = 0;
|
2009-01-08 10:08:56 +08:00
|
|
|
|
2010-02-11 03:12:13 +08:00
|
|
|
get_buffer();
|
|
|
|
buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
|
|
|
|
buffer->input[1] = bd->props.brightness;
|
2009-01-08 10:08:56 +08:00
|
|
|
|
2010-02-11 03:12:13 +08:00
|
|
|
if (buffer->input[0] == -1) {
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-01-08 10:08:56 +08:00
|
|
|
|
|
|
|
if (power_supply_is_system_supplied() > 0)
|
2010-02-11 03:12:13 +08:00
|
|
|
dell_send_request(buffer, 1, 2);
|
2009-01-08 10:08:56 +08:00
|
|
|
else
|
2010-02-11 03:12:13 +08:00
|
|
|
dell_send_request(buffer, 1, 1);
|
2009-01-08 10:08:56 +08:00
|
|
|
|
2010-02-11 03:12:13 +08:00
|
|
|
out:
|
|
|
|
release_buffer();
|
2009-01-08 10:08:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dell_get_intensity(struct backlight_device *bd)
|
|
|
|
{
|
2010-02-11 03:12:13 +08:00
|
|
|
int ret = 0;
|
2009-01-08 10:08:56 +08:00
|
|
|
|
2010-02-11 03:12:13 +08:00
|
|
|
get_buffer();
|
|
|
|
buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
|
2009-01-08 10:08:56 +08:00
|
|
|
|
2010-02-11 03:12:13 +08:00
|
|
|
if (buffer->input[0] == -1) {
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-01-08 10:08:56 +08:00
|
|
|
|
|
|
|
if (power_supply_is_system_supplied() > 0)
|
2010-02-11 03:12:13 +08:00
|
|
|
dell_send_request(buffer, 0, 2);
|
2009-01-08 10:08:56 +08:00
|
|
|
else
|
2010-02-11 03:12:13 +08:00
|
|
|
dell_send_request(buffer, 0, 1);
|
2009-01-08 10:08:56 +08:00
|
|
|
|
2010-02-11 03:12:13 +08:00
|
|
|
out:
|
|
|
|
release_buffer();
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return buffer->output[1];
|
2009-01-08 10:08:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct backlight_ops dell_ops = {
|
|
|
|
.get_brightness = dell_get_intensity,
|
|
|
|
.update_status = dell_send_intensity,
|
|
|
|
};
|
|
|
|
|
2009-12-10 02:23:36 +08:00
|
|
|
bool dell_laptop_i8042_filter(unsigned char data, unsigned char str,
|
|
|
|
struct serio *port)
|
|
|
|
{
|
|
|
|
static bool extended;
|
|
|
|
|
|
|
|
if (str & 0x20)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (unlikely(data == 0xe0)) {
|
|
|
|
extended = true;
|
|
|
|
return false;
|
|
|
|
} else if (unlikely(extended)) {
|
|
|
|
switch (data) {
|
|
|
|
case 0x8:
|
|
|
|
schedule_delayed_work(&dell_rfkill_work,
|
|
|
|
round_jiffies_relative(HZ));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
extended = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-01-08 10:08:56 +08:00
|
|
|
static int __init dell_init(void)
|
|
|
|
{
|
|
|
|
int max_intensity = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!dmi_check_system(dell_device_table))
|
|
|
|
return -ENODEV;
|
|
|
|
|
2009-03-31 03:46:44 +08:00
|
|
|
dmi_walk(find_tokens, NULL);
|
2009-01-08 10:08:56 +08:00
|
|
|
|
|
|
|
if (!da_tokens) {
|
|
|
|
printk(KERN_INFO "dell-laptop: Unable to find dmi tokens\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2009-08-19 22:06:49 +08:00
|
|
|
ret = platform_driver_register(&platform_driver);
|
|
|
|
if (ret)
|
|
|
|
goto fail_platform_driver;
|
|
|
|
platform_device = platform_device_alloc("dell-laptop", -1);
|
|
|
|
if (!platform_device) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto fail_platform_device1;
|
|
|
|
}
|
|
|
|
ret = platform_device_add(platform_device);
|
|
|
|
if (ret)
|
|
|
|
goto fail_platform_device2;
|
|
|
|
|
2010-02-11 03:12:13 +08:00
|
|
|
/*
|
|
|
|
* Allocate buffer below 4GB for SMI data--only 32-bit physical addr
|
|
|
|
* is passed to SMI handler.
|
|
|
|
*/
|
|
|
|
bufferpage = alloc_page(GFP_KERNEL | GFP_DMA32);
|
|
|
|
|
|
|
|
if (!bufferpage)
|
|
|
|
goto fail_buffer;
|
|
|
|
buffer = page_address(bufferpage);
|
|
|
|
mutex_init(&buffer_mutex);
|
|
|
|
|
2009-01-08 10:08:56 +08:00
|
|
|
ret = dell_setup_rfkill();
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
printk(KERN_WARNING "dell-laptop: Unable to setup rfkill\n");
|
2009-08-19 22:06:47 +08:00
|
|
|
goto fail_rfkill;
|
2009-01-08 10:08:56 +08:00
|
|
|
}
|
|
|
|
|
2009-12-10 02:23:36 +08:00
|
|
|
ret = i8042_install_filter(dell_laptop_i8042_filter);
|
|
|
|
if (ret) {
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"dell-laptop: Unable to install key filter\n");
|
|
|
|
goto fail_filter;
|
|
|
|
}
|
|
|
|
|
2009-01-08 10:08:56 +08:00
|
|
|
#ifdef CONFIG_ACPI
|
|
|
|
/* In the event of an ACPI backlight being available, don't
|
|
|
|
* register the platform controller.
|
|
|
|
*/
|
|
|
|
if (acpi_video_backlight_support())
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
|
2010-02-11 03:12:13 +08:00
|
|
|
get_buffer();
|
|
|
|
buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
|
|
|
|
if (buffer->input[0] != -1) {
|
|
|
|
dell_send_request(buffer, 0, 2);
|
|
|
|
max_intensity = buffer->output[3];
|
2009-01-08 10:08:56 +08:00
|
|
|
}
|
2010-02-11 03:12:13 +08:00
|
|
|
release_buffer();
|
2009-01-08 10:08:56 +08:00
|
|
|
|
|
|
|
if (max_intensity) {
|
|
|
|
dell_backlight_device = backlight_device_register(
|
|
|
|
"dell_backlight",
|
2009-08-19 22:06:49 +08:00
|
|
|
&platform_device->dev, NULL,
|
2009-01-08 10:08:56 +08:00
|
|
|
&dell_ops);
|
|
|
|
|
|
|
|
if (IS_ERR(dell_backlight_device)) {
|
|
|
|
ret = PTR_ERR(dell_backlight_device);
|
|
|
|
dell_backlight_device = NULL;
|
2009-08-19 22:06:47 +08:00
|
|
|
goto fail_backlight;
|
2009-01-08 10:08:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dell_backlight_device->props.max_brightness = max_intensity;
|
|
|
|
dell_backlight_device->props.brightness =
|
|
|
|
dell_get_intensity(dell_backlight_device);
|
|
|
|
backlight_update_status(dell_backlight_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-08-19 22:06:47 +08:00
|
|
|
|
|
|
|
fail_backlight:
|
2009-12-10 02:23:36 +08:00
|
|
|
i8042_remove_filter(dell_laptop_i8042_filter);
|
|
|
|
fail_filter:
|
2009-08-19 22:06:48 +08:00
|
|
|
dell_cleanup_rfkill();
|
2009-08-19 22:06:47 +08:00
|
|
|
fail_rfkill:
|
2010-02-11 03:12:13 +08:00
|
|
|
free_page((unsigned long)bufferpage);
|
|
|
|
fail_buffer:
|
2009-08-19 22:06:49 +08:00
|
|
|
platform_device_del(platform_device);
|
|
|
|
fail_platform_device2:
|
|
|
|
platform_device_put(platform_device);
|
|
|
|
fail_platform_device1:
|
|
|
|
platform_driver_unregister(&platform_driver);
|
|
|
|
fail_platform_driver:
|
2009-01-08 10:08:56 +08:00
|
|
|
kfree(da_tokens);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit dell_exit(void)
|
|
|
|
{
|
2009-12-10 02:23:36 +08:00
|
|
|
cancel_delayed_work_sync(&dell_rfkill_work);
|
|
|
|
i8042_remove_filter(dell_laptop_i8042_filter);
|
2009-01-08 10:08:56 +08:00
|
|
|
backlight_device_unregister(dell_backlight_device);
|
2009-08-19 22:06:48 +08:00
|
|
|
dell_cleanup_rfkill();
|
2010-02-10 03:03:04 +08:00
|
|
|
if (platform_device) {
|
|
|
|
platform_device_del(platform_device);
|
|
|
|
platform_driver_unregister(&platform_driver);
|
|
|
|
}
|
2010-02-10 03:05:01 +08:00
|
|
|
kfree(da_tokens);
|
2010-02-11 03:12:13 +08:00
|
|
|
free_page((unsigned long)buffer);
|
2009-01-08 10:08:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(dell_init);
|
|
|
|
module_exit(dell_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
|
|
|
|
MODULE_DESCRIPTION("Dell laptop driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS("dmi:*svnDellInc.:*:ct8:*");
|
2010-02-15 00:53:23 +08:00
|
|
|
MODULE_ALIAS("dmi:*svnDellComputerCorporation.:*:ct8:*");
|