public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Peter F. Patel-Schneider" <pfpschneider@gmail.com>
To: ike.pan@canonical.com, matthew.garrett@nebula.com,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: proposed patch to ideapad-laptop module for Yoga 2 Pro
Date: Fri, 07 Mar 2014 10:22:36 -0800	[thread overview]
Message-ID: <531A0E6C.2070203@gmail.com> (raw)

The Lenovo Ideapad Yoga laptops have a VPC2004 ACPI device, so the
ideapad-laptop module loads for them.  The module enables the Airplane Mode
and Novo keys of the laptop.  Most of the other features of this module
are harmless for these laptops.  However, the laptops do not have hardware
RF kill switches and when the module loads it turns off the WiFi.

This patch adds a flag (rfkill_present) to the ideapad_private data
indicating whether the laptop has an RF kill switch.   On initialization,
there is a check whether the laptop is a Yoga 2 Pro by matching against the
DMI product version of the system information.  If there is a match the flag
is set to false, otherwise it is set to true.  All manipulations of the
rfkill structures are conditioned on this flag being true.

This is a minimal change to make the ideapad-laptop module work correctly
for Yoga 2 Pro Ideapads.  The initialization check should be generalized for
other Ideapads that do not have RF kill switches, particularly other Yogas,
but I do not have precise information on their DMI version information.

What should be done to get this patchapplied?

Peter F. Patel-Schneider

---

--- a/drivers/platform/x86/ideapad-laptop.c
+++ b/drivers/platform/x86/ideapad-laptop.c
@@ -27,6 +27,7 @@
  #include <linux/init.h>
  #include <linux/types.h>
  #include <linux/acpi.h>
+#include <linux/dmi.h>
  #include <linux/rfkill.h>
  #include <linux/platform_device.h>
  #include <linux/input.h>
@@ -84,6 +85,7 @@ struct ideapad_private {
      struct input_dev *inputdev;
      struct backlight_device *blightdev;
      struct dentry *debug;
+        bool rfkill_present;
      unsigned long cfg;
  };

@@ -474,13 +476,15 @@ static void ideapad_sync_rfk_state(struct 
ideapad_private *priv)
      unsigned long hw_blocked;
      int i;

-    if (read_ec_data(priv->adev->handle, VPCCMD_R_RF, &hw_blocked))
-        return;
-    hw_blocked = !hw_blocked;
+    if (priv->rfkill_present) {
+        if (read_ec_data(priv->adev->handle, VPCCMD_R_RF, &hw_blocked))
+            return;
+        hw_blocked = !hw_blocked;

-    for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
-        if (priv->rfk[i])
-            rfkill_set_hw_state(priv->rfk[i], hw_blocked);
+        for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
+            if (priv->rfk[i])
+                rfkill_set_hw_state(priv->rfk[i], hw_blocked);
+    }
  }

  static int ideapad_register_rfkill(struct ideapad_private *priv, int dev)
@@ -825,6 +829,7 @@ static int ideapad_acpi_add(struct platform_device *pdev)
      int cfg;
      struct ideapad_private *priv;
      struct acpi_device *adev;
+    char const *s;

      ret = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev);
      if (ret)
@@ -842,6 +847,15 @@ static int ideapad_acpi_add(struct platform_device *pdev)
      priv->adev = adev;
      priv->platform_device = pdev;

+    /*  check for Yoga 2 Pro, which has no rfkill switches */
+    s = dmi_get_system_info(DMI_PRODUCT_VERSION);
+    if (s && !(strncmp(s, "Lenovo Yoga 2 Pro", 17)) ) {
+        priv->rfkill_present = false;
+    } else {
+        priv->rfkill_present = true;
+    }
+
+
      ret = ideapad_sysfs_init(priv);
      if (ret)
          goto sysfs_failed;
@@ -854,11 +868,13 @@ static int ideapad_acpi_add(struct platform_device *pdev)
      if (ret)
          goto input_failed;

-    for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) {
-        if (test_bit(ideapad_rfk_data[i].cfgbit, &priv->cfg))
-            ideapad_register_rfkill(priv, i);
-        else
-            priv->rfk[i] = NULL;
+    if (priv->rfkill_present) {
+        for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) {
+            if (test_bit(ideapad_rfk_data[i].cfgbit, &priv->cfg))
+                ideapad_register_rfkill(priv, i);
+            else
+                priv->rfk[i] = NULL;
+        }
      }
      ideapad_sync_rfk_state(priv);
      ideapad_sync_touchpad_state(priv);
@@ -877,8 +893,10 @@ static int ideapad_acpi_add(struct platform_device *pdev)
  notification_failed:
      ideapad_backlight_exit(priv);
  backlight_failed:
-    for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
-        ideapad_unregister_rfkill(priv, i);
+    if (priv->rfkill_present) {
+        for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
+            ideapad_unregister_rfkill(priv, i);
+    }
      ideapad_input_exit(priv);
  input_failed:
      ideapad_debugfs_exit(priv);
@@ -897,8 +915,10 @@ static int ideapad_acpi_remove(struct platform_device *pdev)
      acpi_remove_notify_handler(priv->adev->handle,
          ACPI_DEVICE_NOTIFY, ideapad_acpi_notify);
      ideapad_backlight_exit(priv);
-    for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
-        ideapad_unregister_rfkill(priv, i);
+    if (priv->rfkill_present) {
+        for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
+            ideapad_unregister_rfkill(priv, i);
+    }
      ideapad_input_exit(priv);
      ideapad_debugfs_exit(priv);
      ideapad_sysfs_exit(priv);


                 reply	other threads:[~2014-03-07 18:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=531A0E6C.2070203@gmail.com \
    --to=pfpschneider@gmail.com \
    --cc=ike.pan@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew.garrett@nebula.com \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox