Re: [RFT] hp-wmi: improved rfkill support for wifi

From: Maciej Rutecki
Date: Mon Jul 20 2009 - 15:55:05 EST


2009/7/20 Alan Jenkins <alan-jenkins@xxxxxxxxxxxxxx>:
>
> ...and here's the version that remembers to register the bluetooth. ÂI
> reviewed the patch again; hopefully that's the last dumb error.
[...]

2.6.31-rc3+ patches:
http://lkml.org/lkml/2009/7/18/131
http://lkml.org/lkml/2009/7/10/339
+ patch below:

> diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
> index 517ac47..adb26d3 100644
> --- a/drivers/platform/x86/hp-wmi.c
> +++ b/drivers/platform/x86/hp-wmi.c
> @@ -51,6 +51,12 @@ MODULE_ALIAS("wmi:5FB7F034-2C63-45e9-BE91-3D44E2C707E4");
> Â#define HPWMI_WIRELESS_QUERY 0x5
> Â#define HPWMI_HOTKEY_QUERY 0xc
>
> +enum hp_wmi_radio {
> + Â Â Â HPWMI_WIFI = 0,
> + Â Â Â HPWMI_BLUETOOTH = 1,
> + Â Â Â HPWMI_WWAN = 2,
> +};
> +
> Âstatic int __init hp_wmi_bios_setup(struct platform_device *device);
> Âstatic int __exit hp_wmi_bios_remove(struct platform_device *device);
> Âstatic int hp_wmi_resume_handler(struct platform_device *device);
> @@ -170,8 +176,8 @@ static int hp_wmi_tablet_state(void)
>
> Âstatic int hp_wmi_set_block(void *data, bool blocked)
> Â{
> - Â Â Â unsigned long b = (unsigned long) data;
> - Â Â Â int query = BIT(b + 8) | ((!blocked) << b);
> + Â Â Â enum hp_wmi_radio r = (enum hp_wmi_radio) data;
> + Â Â Â int query = BIT(r + 8) | ((!blocked) << r);
>
> Â Â Â Âreturn hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, query);
> Â}
> @@ -180,41 +186,23 @@ static const struct rfkill_ops hp_wmi_rfkill_ops = {
> Â Â Â Â.set_block = hp_wmi_set_block,
> Â};
>
> -static bool hp_wmi_wifi_sw_state(void)
> +static bool hp_wmi_get_sw_state(enum hp_wmi_radio r)
> Â{
> Â Â Â Âint wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
> + Â Â Â int mask = 0x200 << (r * 8);
>
> - Â Â Â if (wireless & 0x200)
> + Â Â Â if (wireless & mask)
> Â Â Â Â Â Â Â Âreturn false;
> Â Â Â Âelse
> Â Â Â Â Â Â Â Âreturn true;
> Â}
>
> -static bool hp_wmi_wifi_hw_state(void)
> +static bool hp_wmi_get_hw_state(enum hp_wmi_radio r)
> Â{
> Â Â Â Âint wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
> + Â Â Â int mask = 0x800 << (r * 8);
>
> - Â Â Â if (wireless & 0x800)
> - Â Â Â Â Â Â Â return false;
> - Â Â Â else
> - Â Â Â Â Â Â Â return true;
> -}
> -
> -static bool hp_wmi_bluetooth_state(void)
> -{
> - Â Â Â int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
> -
> - Â Â Â if (wireless & 0x10000)
> - Â Â Â Â Â Â Â return false;
> - Â Â Â else
> - Â Â Â Â Â Â Â return true;
> -}
> -
> -static bool hp_wmi_wwan_state(void)
> -{
> - Â Â Â int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
> -
> - Â Â Â if (wireless & 0x1000000)
> + Â Â Â if (wireless & mask)
> Â Â Â Â Â Â Â Âreturn false;
> Â Â Â Âelse
> Â Â Â Â Â Â Â Âreturn true;
> @@ -339,50 +327,55 @@ static void hp_wmi_notify(u32 value, void *context)
> Â Â Â Âstruct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
> Â Â Â Âstatic struct key_entry *key;
> Â Â Â Âunion acpi_object *obj;
> + Â Â Â int eventcode;
>
> Â Â Â Âwmi_get_event_data(value, &response);
>
> Â Â Â Âobj = (union acpi_object *)response.pointer;
>
> - Â Â Â if (obj && obj->type == ACPI_TYPE_BUFFER && obj->buffer.length == 8) {
> - Â Â Â Â Â Â Â int eventcode = *((u8 *) obj->buffer.pointer);
> - Â Â Â Â Â Â Â if (eventcode == 0x4)
> - Â Â Â Â Â Â Â Â Â Â Â eventcode = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â0);
> - Â Â Â Â Â Â Â key = hp_wmi_get_entry_by_scancode(eventcode);
> - Â Â Â Â Â Â Â if (key) {
> - Â Â Â Â Â Â Â Â Â Â Â switch (key->type) {
> - Â Â Â Â Â Â Â Â Â Â Â case KE_KEY:
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â input_report_key(hp_wmi_input_dev,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âkey->keycode, 1);
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â input_sync(hp_wmi_input_dev);
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â input_report_key(hp_wmi_input_dev,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âkey->keycode, 0);
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â input_sync(hp_wmi_input_dev);
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â break;
> - Â Â Â Â Â Â Â Â Â Â Â }
> - Â Â Â Â Â Â Â } else if (eventcode == 0x1) {
> - Â Â Â Â Â Â Â Â Â Â Â input_report_switch(hp_wmi_input_dev, SW_DOCK,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_dock_state());
> - Â Â Â Â Â Â Â Â Â Â Â input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_tablet_state());
> + Â Â Â if (!obj || obj->type != ACPI_TYPE_BUFFER || obj->buffer.length != 8) {
> + Â Â Â Â Â Â Â printk(KERN_INFO "HP WMI: Unknown response received\n");
> + Â Â Â Â Â Â Â return;
> + Â Â Â }
> +
> + Â Â Â eventcode = *((u8 *) obj->buffer.pointer);
> + Â Â Â if (eventcode == 0x4)
> + Â Â Â Â Â Â Â eventcode = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0);
> + Â Â Â key = hp_wmi_get_entry_by_scancode(eventcode);
> + Â Â Â if (key) {
> + Â Â Â Â Â Â Â switch (key->type) {
> + Â Â Â Â Â Â Â case KE_KEY:
> + Â Â Â Â Â Â Â Â Â Â Â input_report_key(hp_wmi_input_dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âkey->keycode, 1);
> + Â Â Â Â Â Â Â Â Â Â Â input_sync(hp_wmi_input_dev);
> + Â Â Â Â Â Â Â Â Â Â Â input_report_key(hp_wmi_input_dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âkey->keycode, 0);
> Â Â Â Â Â Â Â Â Â Â Â Âinput_sync(hp_wmi_input_dev);
> - Â Â Â Â Â Â Â } else if (eventcode == 0x5) {
> - Â Â Â Â Â Â Â Â Â Â Â if (wifi_rfkill)
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â rfkill_set_states(wifi_rfkill,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_wifi_sw_state(),
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_wifi_hw_state());
> - Â Â Â Â Â Â Â Â Â Â Â if (bluetooth_rfkill)
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â rfkill_set_sw_state(bluetooth_rfkill,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_bluetooth_state());
> - Â Â Â Â Â Â Â Â Â Â Â if (wwan_rfkill)
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â rfkill_set_sw_state(wwan_rfkill,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_wwan_state());
> - Â Â Â Â Â Â Â } else
> - Â Â Â Â Â Â Â Â Â Â Â printk(KERN_INFO "HP WMI: Unknown key pressed - %x\n",
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âeventcode);
> + Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â Â Â Â Â }
> + Â Â Â } else if (eventcode == 0x1) {
> + Â Â Â Â Â Â Â input_report_switch(hp_wmi_input_dev, SW_DOCK,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_dock_state());
> + Â Â Â Â Â Â Â input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_tablet_state());
> + Â Â Â Â Â Â Â input_sync(hp_wmi_input_dev);
> + Â Â Â } else if (eventcode == 0x5) {
> + Â Â Â Â Â Â Â if (wifi_rfkill)
> + Â Â Â Â Â Â Â Â Â Â Â rfkill_set_states(wifi_rfkill,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_get_sw_state(HPWMI_WIFI),
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_get_hw_state(HPWMI_WIFI));
> + Â Â Â Â Â Â Â if (bluetooth_rfkill)
> + Â Â Â Â Â Â Â Â Â Â Â rfkill_set_states(bluetooth_rfkill,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
> + Â Â Â Â Â Â Â if (wwan_rfkill)
> + Â Â Â Â Â Â Â Â Â Â Â rfkill_set_states(wwan_rfkill,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_get_sw_state(HPWMI_WWAN),
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_get_hw_state(HPWMI_WWAN));
> Â Â Â Â} else
> - Â Â Â Â Â Â Â printk(KERN_INFO "HP WMI: Unknown response received\n");
> + Â Â Â Â Â Â Â printk(KERN_INFO "HP WMI: Unknown key pressed - %x\n",
> + Â Â Â Â Â Â Â Â Â Â Â eventcode);
> Â}
>
> Âstatic int __init hp_wmi_input_setup(void)
> @@ -461,11 +454,11 @@ static int __init hp_wmi_bios_setup(struct platform_device *device)
> Â Â Â Â Â Â Â Âwifi_rfkill = rfkill_alloc("hp-wifi", &device->dev,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â RFKILL_TYPE_WLAN,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &hp_wmi_rfkill_ops,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â(void *) 0);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â(void *) HPWMI_WIFI);
> Â Â Â Â Â Â Â Ârfkill_init_sw_state(wifi_rfkill,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âhp_wmi_wifi_sw_state());
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âhp_wmi_get_sw_state(HPWMI_WIFI));
> Â Â Â Â Â Â Â Ârfkill_set_hw_state(wifi_rfkill,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_wifi_hw_state());
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_get_hw_state(HPWMI_WIFI));
> Â Â Â Â Â Â Â Âerr = rfkill_register(wifi_rfkill);
> Â Â Â Â Â Â Â Âif (err)
> Â Â Â Â Â Â Â Â Â Â Â Âgoto register_wifi_error;
> @@ -475,7 +468,11 @@ static int __init hp_wmi_bios_setup(struct platform_device *device)
> Â Â Â Â Â Â Â Âbluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂRFKILL_TYPE_BLUETOOTH,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â&hp_wmi_rfkill_ops,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (void *) 1);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (void *) HPWMI_BLUETOOTH);
> + Â Â Â Â Â Â Â rfkill_init_sw_state(bluetooth_rfkill,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âhp_wmi_get_sw_state(HPWMI_BLUETOOTH));
> + Â Â Â Â Â Â Â rfkill_set_hw_state(bluetooth_rfkill,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
> Â Â Â Â Â Â Â Âerr = rfkill_register(bluetooth_rfkill);
> Â Â Â Â Â Â Â Âif (err)
> Â Â Â Â Â Â Â Â Â Â Â Âgoto register_bluetooth_error;
> @@ -485,7 +482,11 @@ static int __init hp_wmi_bios_setup(struct platform_device *device)
> Â Â Â Â Â Â Â Âwwan_rfkill = rfkill_alloc("hp-wwan", &device->dev,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â RFKILL_TYPE_WWAN,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &hp_wmi_rfkill_ops,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â(void *) 2);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â(void *) HPWMI_WWAN);
> + Â Â Â Â Â Â Â rfkill_init_sw_state(wwan_rfkill,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âhp_wmi_get_sw_state(HPWMI_WWAN));
> + Â Â Â Â Â Â Â rfkill_set_hw_state(wwan_rfkill,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_get_hw_state(HPWMI_WWAN));
> Â Â Â Â Â Â Â Âerr = rfkill_register(wwan_rfkill);
> Â Â Â Â Â Â Â Âif (err)
> Â Â Â Â Â Â Â Â Â Â Â Âgoto register_wwan_err;
> @@ -541,9 +542,18 @@ static int hp_wmi_resume_handler(struct platform_device *device)
> Â Â Â Â Â Â Â Â Â Â Â Â Â Âhp_wmi_tablet_state());
> Â Â Â Âinput_sync(hp_wmi_input_dev);
>
> - Â Â Â rfkill_set_states(wifi_rfkill,
> - Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_wifi_sw_state(),
> - Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_wifi_hw_state());
> + Â Â Â if (wifi_rfkill)
> + Â Â Â Â Â Â Â rfkill_set_states(wifi_rfkill,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_get_sw_state(HPWMI_WIFI),
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_get_hw_state(HPWMI_WIFI));
> + Â Â Â if (bluetooth_rfkill)
> + Â Â Â Â Â Â Â rfkill_set_states(bluetooth_rfkill,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
> + Â Â Â if (wwan_rfkill)
> + Â Â Â Â Â Â Â rfkill_set_states(wwan_rfkill,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_get_sw_state(HPWMI_WWAN),
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hp_wmi_get_hw_state(HPWMI_WWAN));
>
> Â Â Â Âreturn 0;
> Â}
>
>
>

root@gumis:/home/maciek/zrodelka/rfkill/rfkill# ./rfkill list
0: phy0: Wireless LAN
Soft blocked: yes
Hard blocked: yes
1: hp-wifi: Wireless LAN
Soft blocked: yes
Hard blocked: no
2: hp-bluetooth: Bluetooth
Soft blocked: yes
Hard blocked: no
root@gumis:/home/maciek/zrodelka/rfkill/rfkill# ./rfkill unblock 0
root@gumis:/home/maciek/zrodelka/rfkill/rfkill# ./rfkill list
0: phy0: Wireless LAN
Soft blocked: no
Hard blocked: yes
1: hp-wifi: Wireless LAN
Soft blocked: yes
Hard blocked: no
2: hp-bluetooth: Bluetooth
Soft blocked: yes
Hard blocked: no
root@gumis:/home/maciek/zrodelka/rfkill/rfkill# ./rfkill unblock 1
root@gumis:/home/maciek/zrodelka/rfkill/rfkill# ./rfkill list
0: phy0: Wireless LAN
Soft blocked: no
Hard blocked: no
1: hp-wifi: Wireless LAN
Soft blocked: no
Hard blocked: no
2: hp-bluetooth: Bluetooth
Soft blocked: yes
Hard blocked: no
root@gumis:/home/maciek/zrodelka/rfkill/rfkill# ./rfkill unblock 2
root@gumis:/home/maciek/zrodelka/rfkill/rfkill# ./rfkill list
0: phy0: Wireless LAN
Soft blocked: no
Hard blocked: no
1: hp-wifi: Wireless LAN
Soft blocked: no
Hard blocked: no
2: hp-bluetooth: Bluetooth
Soft blocked: no
Hard blocked: no
3: hci0: Bluetooth
Soft blocked: yes
Hard blocked: no
root@gumis:/home/maciek/zrodelka/rfkill/rfkill# ./rfkill unblock 3
root@gumis:/home/maciek/zrodelka/rfkill/rfkill# ./rfkill list
0: phy0: Wireless LAN
Soft blocked: no
Hard blocked: no
1: hp-wifi: Wireless LAN
Soft blocked: no
Hard blocked: no
2: hp-bluetooth: Bluetooth
Soft blocked: no
Hard blocked: no
3: hci0: Bluetooth
Soft blocked: no
Hard blocked: no
root@gumis:/home/maciek/zrodelka/rfkill/rfkill# hciconfig
hci0: Type: USB
BD Address: 00:16:41:88:A0:1B ACL MTU: 1017:8 SCO MTU: 64:8
DOWN
RX bytes:318 acl:0 sco:0 events:6 errors:0
TX bytes:27 acl:0 sco:0 commands:9 errors:0

Works OK. Thanks :-)

During compile I have got:
CC [M] drivers/platform/x86/hp-wmi.o
drivers/platform/x86/hp-wmi.c: In function âhp_wmi_bios_setupâ:
drivers/platform/x86/hp-wmi.c:460: warning: ignoring return value of
ârfkill_set_hw_stateâ, declared with attribute warn_unused_result
drivers/platform/x86/hp-wmi.c:474: warning: ignoring return value of
ârfkill_set_hw_stateâ, declared with attribute warn_unused_result
drivers/platform/x86/hp-wmi.c:488: warning: ignoring return value of
ârfkill_set_hw_stateâ, declared with attribute warn_unused_result

root@gumis:/home/maciek# gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian
4.3.3-13' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--enable-shared --enable-multiarch --with-system-zlib
--libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc
--enable-mpfr --enable-targets=all --with-tune=generic
--enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
--target=i486-linux-gnu
Thread model: posix
gcc version 4.3.3 (Debian 4.3.3-13)

Regards
--
Maciej Rutecki
http://www.maciek.unixy.pl
èº{.nÇ+‰·Ÿ®‰­†+%ŠËlzwm…ébëæìr¸›zX§»®w¥Š{ayºÊÚë,j­¢f£¢·hš‹àz¹®w¥¢¸ ¢·¦j:+v‰¨ŠwèjØm¶Ÿÿ¾«‘êçzZ+ƒùšŽŠÝj"ú!¶iO•æ¬z·švØ^¶m§ÿðà nÆàþY&—