aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/platform
diff options
context:
space:
mode:
authorCorentin Chary <corentincj@iksaif.net>2011-02-06 07:28:31 -0500
committerMatthew Garrett <mjg@redhat.com>2011-03-28 06:05:16 -0400
commit5c95638d115f9c6661fff254b3beb14b19f88e41 (patch)
treea8028278fafc70dc2c363b437ab88a4e54124a5c /drivers/platform
parent7898cf1a3665d22c4d16308f73e981c6464be81b (diff)
eeepc-wmi: add an helper using simple return codes
eeepc_wmi_get_devstate returns an acpi_status, so each call need extra logic to handle the return code. This patch add a simple getter, returning a boolean (or a negative error code). Signed-off-by: Corentin Chary <corentincj@iksaif.net> Signed-off-by: Matthew Garrett <mjg@redhat.com>
Diffstat (limited to 'drivers/platform')
-rw-r--r--drivers/platform/x86/eeepc-wmi.c96
1 files changed, 39 insertions, 57 deletions
diff --git a/drivers/platform/x86/eeepc-wmi.c b/drivers/platform/x86/eeepc-wmi.c
index d8234582b54..de501fb3d1b 100644
--- a/drivers/platform/x86/eeepc-wmi.c
+++ b/drivers/platform/x86/eeepc-wmi.c
@@ -257,6 +257,29 @@ static acpi_status eeepc_wmi_set_devstate(u32 dev_id, u32 ctrl_param,
257 return status; 257 return status;
258} 258}
259 259
260/* Helper for special devices with magic return codes */
261static int eeepc_wmi_get_devstate_simple(u32 dev_id)
262{
263 u32 retval = 0;
264 acpi_status status;
265
266 status = eeepc_wmi_get_devstate(dev_id, &retval);
267
268 if (ACPI_FAILURE(status))
269 return -EINVAL;
270
271 /* If the device is present, DSTS will always set some bits
272 * 0x00070000 - 1110000000000000000 - device supported
273 * 0x00060000 - 1100000000000000000 - not supported
274 * 0x00020000 - 0100000000000000000 - device supported
275 * 0x00010000 - 0010000000000000000 - not supported / special mode ?
276 */
277 if (!retval || retval == 0x00060000)
278 return -ENODEV;
279
280 return retval & 0x1;
281}
282
260/* 283/*
261 * LEDs 284 * LEDs
262 */ 285 */
@@ -290,23 +313,7 @@ static void tpd_led_set(struct led_classdev *led_cdev,
290 313
291static int read_tpd_state(struct eeepc_wmi *eeepc) 314static int read_tpd_state(struct eeepc_wmi *eeepc)
292{ 315{
293 u32 retval; 316 return eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_TPDLED);
294 acpi_status status;
295
296 status = eeepc_wmi_get_devstate(EEEPC_WMI_DEVID_TPDLED, &retval);
297
298 if (ACPI_FAILURE(status))
299 return -1;
300 else if (!retval || retval == 0x00060000)
301 /*
302 * if touchpad led is present, DSTS will set some bits,
303 * usually 0x00020000.
304 * 0x00060000 means that the device is not supported
305 */
306 return -ENODEV;
307 else
308 /* Status is stored in the first bit */
309 return retval & 0x1;
310} 317}
311 318
312static enum led_brightness tpd_led_get(struct led_classdev *led_cdev) 319static enum led_brightness tpd_led_get(struct led_classdev *led_cdev)
@@ -358,15 +365,11 @@ static void eeepc_wmi_led_exit(struct eeepc_wmi *eeepc)
358 */ 365 */
359static bool eeepc_wlan_rfkill_blocked(struct eeepc_wmi *eeepc) 366static bool eeepc_wlan_rfkill_blocked(struct eeepc_wmi *eeepc)
360{ 367{
361 u32 retval; 368 int result = eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WLAN);
362 acpi_status status;
363
364 status = eeepc_wmi_get_devstate(EEEPC_WMI_DEVID_WLAN, &retval);
365 369
366 if (ACPI_FAILURE(status)) 370 if (result < 0)
367 return false; 371 return false;
368 372 return !result;
369 return !(retval & 0x1);
370} 373}
371 374
372static void eeepc_rfkill_hotplug(struct eeepc_wmi *eeepc) 375static void eeepc_rfkill_hotplug(struct eeepc_wmi *eeepc)
@@ -494,19 +497,12 @@ static void eeepc_unregister_rfkill_notifier(struct eeepc_wmi *eeepc,
494static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot, 497static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot,
495 u8 *value) 498 u8 *value)
496{ 499{
497 u32 retval; 500 int result = eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WLAN);
498 acpi_status status;
499
500 status = eeepc_wmi_get_devstate(EEEPC_WMI_DEVID_WLAN, &retval);
501
502 if (ACPI_FAILURE(status))
503 return -EIO;
504 501
505 if (!retval || retval == 0x00060000) 502 if (result < 0)
506 return -ENODEV; 503 return result;
507 else
508 *value = (retval & 0x1);
509 504
505 *value = !!result;
510 return 0; 506 return 0;
511} 507}
512 508
@@ -601,15 +597,14 @@ static int eeepc_rfkill_set(void *data, bool blocked)
601static void eeepc_rfkill_query(struct rfkill *rfkill, void *data) 597static void eeepc_rfkill_query(struct rfkill *rfkill, void *data)
602{ 598{
603 int dev_id = (unsigned long)data; 599 int dev_id = (unsigned long)data;
604 u32 retval; 600 int result;
605 acpi_status status;
606 601
607 status = eeepc_wmi_get_devstate(dev_id, &retval); 602 result = eeepc_wmi_get_devstate_simple(dev_id);
608 603
609 if (ACPI_FAILURE(status)) 604 if (result < 0)
610 return ; 605 return ;
611 606
612 rfkill_set_sw_state(rfkill, !(retval & 0x1)); 607 rfkill_set_sw_state(rfkill, !result);
613} 608}
614 609
615static int eeepc_rfkill_wlan_set(void *data, bool blocked) 610static int eeepc_rfkill_wlan_set(void *data, bool blocked)
@@ -650,23 +645,10 @@ static int eeepc_new_rfkill(struct eeepc_wmi *eeepc,
650 const char *name, 645 const char *name,
651 enum rfkill_type type, int dev_id) 646 enum rfkill_type type, int dev_id)
652{ 647{
653 int result; 648 int result = eeepc_wmi_get_devstate_simple(dev_id);
654 u32 retval;
655 acpi_status status;
656
657 status = eeepc_wmi_get_devstate(dev_id, &retval);
658 649
659 if (ACPI_FAILURE(status)) 650 if (result < 0)
660 return -1; 651 return result;
661
662 /* If the device is present, DSTS will always set some bits
663 * 0x00070000 - 1110000000000000000 - device supported
664 * 0x00060000 - 1100000000000000000 - not supported
665 * 0x00020000 - 0100000000000000000 - device supported
666 * 0x00010000 - 0010000000000000000 - not supported / special mode ?
667 */
668 if (!retval || retval == 0x00060000)
669 return -ENODEV;
670 652
671 if (dev_id == EEEPC_WMI_DEVID_WLAN && eeepc->hotplug_wireless) 653 if (dev_id == EEEPC_WMI_DEVID_WLAN && eeepc->hotplug_wireless)
672 *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type, 654 *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type,
@@ -678,7 +660,7 @@ static int eeepc_new_rfkill(struct eeepc_wmi *eeepc,
678 if (!*rfkill) 660 if (!*rfkill)
679 return -EINVAL; 661 return -EINVAL;
680 662
681 rfkill_init_sw_state(*rfkill, !(retval & 0x1)); 663 rfkill_init_sw_state(*rfkill, !result);
682 result = rfkill_register(*rfkill); 664 result = rfkill_register(*rfkill);
683 if (result) { 665 if (result) {
684 rfkill_destroy(*rfkill); 666 rfkill_destroy(*rfkill);