All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH 58/62] msi-laptop: Support some MSI 3G netbook that is need load SCM
@ 2010-03-03  4:52 Joey Lee
  2010-03-03 13:45 ` Matthew Garrett
  0 siblings, 1 reply; 11+ messages in thread
From: Joey Lee @ 2010-03-03  4:52 UTC (permalink / raw)
  To: mjg59; +Cc: mzxreary, gregkh, linux-kernel

Hi Matthew, 

First, thank's for your kindly review and suggestion to me.

於 二,2010-03-02 於 15:46 -0800,Greg KH 提到:
> On Tue, Mar 02, 2010 at 11:39:29PM +0000, Matthew Garrett wrote:
> > On Tue, Mar 02, 2010 at 03:28:57PM -0800, Greg Kroah-Hartman wrote:
> > > From: Lee, Chun-Yi <jlee@novell.com>
> > > 
> > > Some MSI 3G netbook only have one fn key to control Wlan/Bluetooth/3G,
> > > those netbook will load the SCM (windows app) to disable the original
> > > Wlan/Bluetooth control by BIOS when user press fn key, then control
> > > Wlan/Bluetooth/3G by SCM (software control by OS). Without SCM, user
> > > cann't on/off 3G module on those 3G netbook.
> > > On Linux, msi-laptop driver will do the same thing to disable the
> > > original BIOS control, then might need use HAL or other userland
> > > application to do the software control that simulate with SCM.
> > > e.g. MSI N034 netbook
> > 
> > How does the function key event get reported to userland? This should 
> > generate KEY_RFKILL and then just go through rfkill-input.

I developed this driver on 2.6.31 kernel, and I found this key code is
in 2.6.33 kernel and later.
There have one and only one scancode to control 3 devices when end user
press fn+f11 key on MSI N034.
Currently, we setup this mapping in HAL key and mapping it to KEY_WLAN.

Does that means I need mapping the scancode to KEY_RFKILL in msi-laptop
driver for 2.6.33 kernel?
If YES, I will submit another patch to add this scancode/keycode mapping
in msi-laptop.c

> I'm pretty sure that Joey is using rfkill here, but I didn't realize
> that it also supported an input device.
> 
> This code is just detecting the keypress, and acting on it, I think,
> right Joey?  Isn't that the way this is supposed to work?  Or is it
> supposed to use rfkill-input, which then userspace turns around and
> calls the other rfkill interface to then disable the wireless?  If so, I
> think a number of laptop drivers need to be changed to do this.
> 

There have a serial MSI netbook (like: N034) use only one scancode (one
function key) to control 3 devices (Wlan/Bluetooth/3G). It have a
sequence to control those device and userland application control this
sequence, almost like:
	- Bluetooth on, WLAN on, WWAN on
	- Bluetooth on, WLAN off, WWAN off
	- Bluetooth off, WLAN off, WWAN on
	....
	- Bluetooth off, WLAN off, WWAN off

Even on Windows platform, this job is also handle by userland
application, not by hardware or driver. And MSI EC provide a address to
turn on/off those devices' power and led light.

This patchset for msi-laptop driver is just to provide Wlan/Bluetooth/3G
rfkill sysfs interface for userland to turn on/off those devices's power
and led.
And this patchset doesn't do:
    - setup the wifi function key scancode/keycode mapping.
    - control those 3 devices on/off sequence. (userland control it)


Thank's
Joey Lee


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 58/62] msi-laptop: Support some MSI 3G netbook that is need load SCM
  2010-03-03  4:52 [PATCH 58/62] msi-laptop: Support some MSI 3G netbook that is need load SCM Joey Lee
@ 2010-03-03 13:45 ` Matthew Garrett
  0 siblings, 0 replies; 11+ messages in thread
From: Matthew Garrett @ 2010-03-03 13:45 UTC (permalink / raw)
  To: Joey Lee; +Cc: mzxreary, gregkh, linux-kernel

On Tue, Mar 02, 2010 at 09:52:12PM -0700, Joey Lee wrote:

> I developed this driver on 2.6.31 kernel, and I found this key code is
> in 2.6.33 kernel and later.
> There have one and only one scancode to control 3 devices when end user
> press fn+f11 key on MSI N034.
> Currently, we setup this mapping in HAL key and mapping it to KEY_WLAN.

Ah! The key comes through the keyboard controller? In that case, yeah, 
just map it to KEY_RFKILL in hal isntead of KEY_WLAN. Everything should 
work fine then. If rfkill-input is configured, it'll kill all the 
radios. If userland claims it instead, it can cycle through with 
whatever policy is desired.

-- 
Matthew Garrett | mjg59@srcf.ucam.org

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 58/62] msi-laptop: Support some MSI 3G netbook that is need load SCM
  2010-03-09 21:01 ` Greg KH
@ 2010-03-09 21:14   ` Matthew Garrett
  0 siblings, 0 replies; 11+ messages in thread
From: Matthew Garrett @ 2010-03-09 21:14 UTC (permalink / raw)
  To: Greg KH; +Cc: Joey Lee, mzxreary, linux-kernel

On Tue, Mar 09, 2010 at 01:01:50PM -0800, Greg KH wrote:
> On Tue, Mar 09, 2010 at 05:42:58AM -0700, Joey Lee wrote:
> > Hi Greg, 
> > 
> > Please kindly review the attached patch for removed the non-standard
> > interface "threeg" in msi-laptop driver.
> 
> Looks good to me.
> 
> Matthew, are you going to be taking patches like this now?

I am.

> If so, feel free to add:
> 	Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
> to the patch.

Will do.

Thanks,
-- 
Matthew Garrett | mjg59@srcf.ucam.org

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 58/62] msi-laptop: Support some MSI 3G netbook that is need load SCM
  2010-03-09 12:42 Joey Lee
@ 2010-03-09 21:01 ` Greg KH
  2010-03-09 21:14   ` Matthew Garrett
  0 siblings, 1 reply; 11+ messages in thread
From: Greg KH @ 2010-03-09 21:01 UTC (permalink / raw)
  To: Joey Lee; +Cc: mzxreary, mjg59, linux-kernel

On Tue, Mar 09, 2010 at 05:42:58AM -0700, Joey Lee wrote:
> Hi Greg, 
> 
> Please kindly review the attached patch for removed the non-standard
> interface "threeg" in msi-laptop driver.

Looks good to me.

Matthew, are you going to be taking patches like this now?

If so, feel free to add:
	Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
to the patch.

If not, please let me know.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 58/62] msi-laptop: Support some MSI 3G netbook that is need load SCM
@ 2010-03-09 12:42 Joey Lee
  2010-03-09 21:01 ` Greg KH
  0 siblings, 1 reply; 11+ messages in thread
From: Joey Lee @ 2010-03-09 12:42 UTC (permalink / raw)
  To: gregkh; +Cc: mzxreary, mjg59, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 868 bytes --]

Hi Greg, 

Please kindly review the attached patch for removed the non-standard
interface "threeg" in msi-laptop driver.



Thank's a lot!
Joey Lee

於 五,2010-03-05 於 06:10 +0000,joeyli(Joey Lee) 提到:
> Hi Matthew, 
> 
> 於 四,2010-03-04 於 17:09 +0000,Matthew Garrett 提到:
> > On Thu, Mar 04, 2010 at 10:07:53AM -0700, Joey Lee wrote:
> > > Thank's for your review and suggestion.
> > > Per discuss for msi-laptop patchset, I will submit a bit patch for the
> > > following change:
> > > 	- remove threeg sysfs interface.
> > > 	- add KEY_RFKILL keymapping to msi-laptop.
> > 
> > If the key event comes through the keyboard controller, there's no need 
> > to add the mapping to msi-laptop. Doing it through udev or hal is fine.
> > 
> 
> Thank's fully undertood, now, will send patch for remove threeg sysfs
> interface.
> 
> 
> Joey Lee


[-- Attachment #2: 0006-Removed-non-standard-interface-threeg.patch --]
[-- Type: text/plain, Size: 3198 bytes --]

>From c9dc06048fcb0b8fadd510ef26b5af7b466aeab6 Mon Sep 17 00:00:00 2001
From: Lee, Chun-Yi <jlee@novell.com>
Date: Tue, 9 Mar 2010 20:25:42 +0800
Subject: [PATCH] Removed non-standard interface "threeg"

There already have standard rfkill wwan interface for 3G device, so, removed
non-standard interface "threeg".

Signed-off-by: Lee, Chun-Yi <jlee@novell.com>
---
 drivers/platform/x86/msi-laptop.c |   36 ------------------------------------
 1 files changed, 0 insertions(+), 36 deletions(-)

diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
index c2b05da..c891522 100644
--- a/drivers/platform/x86/msi-laptop.c
+++ b/drivers/platform/x86/msi-laptop.c
@@ -311,29 +311,6 @@ static ssize_t store_bluetooth(struct device *dev,
 	return set_device_state(buf, count, MSI_STANDARD_EC_BLUETOOTH_MASK);
 }
 
-static ssize_t show_threeg(struct device *dev,
-	struct device_attribute *attr, char *buf)
-{
-
-	int ret;
-
-	/* old msi ec not support 3G */
-	if (old_ec_model)
-		return -1;
-
-	ret = get_wireless_state_ec_standard();
-	if (ret < 0)
-		return ret;
-
-	return sprintf(buf, "%i\n", threeg_s);
-}
-
-static ssize_t store_threeg(struct device *dev,
-	struct device_attribute *attr, const char *buf, size_t count)
-{
-	return set_device_state(buf, count, MSI_STANDARD_EC_3G_MASK);
-}
-
 static ssize_t show_lcd_level(struct device *dev,
 	struct device_attribute *attr, char *buf)
 {
@@ -396,7 +373,6 @@ static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level);
 static DEVICE_ATTR(auto_brightness, 0644, show_auto_brightness, store_auto_brightness);
 static DEVICE_ATTR(bluetooth, 0444, show_bluetooth, NULL);
 static DEVICE_ATTR(wlan, 0444, show_wlan, NULL);
-static DEVICE_ATTR(threeg, 0444, show_threeg, NULL);
 
 static struct attribute *msipf_attributes[] = {
 	&dev_attr_lcd_level.attr,
@@ -635,10 +611,8 @@ static int load_scm_model_init(struct platform_device *sdev)
 	/* allow userland write sysfs file  */
 	dev_attr_bluetooth.store = store_bluetooth;
 	dev_attr_wlan.store = store_wlan;
-	dev_attr_threeg.store = store_threeg;
 	dev_attr_bluetooth.attr.mode |= S_IWUSR;
 	dev_attr_wlan.attr.mode |= S_IWUSR;
-	dev_attr_threeg.attr.mode |= S_IWUSR;
 
 	/* disable hardware control by fn key */
 	result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
@@ -715,14 +689,6 @@ static int __init msi_init(void)
 	if (ret)
 		goto fail_platform_device2;
 
-	if (!old_ec_model) {
-		if (threeg_exists)
-			ret = device_create_file(&msipf_device->dev,
-						&dev_attr_threeg);
-		if (ret)
-			goto fail_platform_device2;
-	}
-
 	/* Disable automatic brightness control by default because
 	 * this module was probably loaded to do brightness control in
 	 * software. */
@@ -757,8 +723,6 @@ static void __exit msi_cleanup(void)
 {
 
 	sysfs_remove_group(&msipf_device->dev.kobj, &msipf_attribute_group);
-	if (!old_ec_model && threeg_exists)
-		device_remove_file(&msipf_device->dev, &dev_attr_threeg);
 	platform_device_unregister(msipf_device);
 	platform_driver_unregister(&msipf_driver);
 	backlight_device_unregister(msibl_device);
-- 
1.6.0.2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 58/62] msi-laptop: Support some MSI 3G netbook that is need load SCM
@ 2010-03-05  6:10 Joey Lee
  0 siblings, 0 replies; 11+ messages in thread
From: Joey Lee @ 2010-03-05  6:10 UTC (permalink / raw)
  To: mjg59; +Cc: mzxreary, gregkh, linux-kernel

Hi Matthew, 

於 四,2010-03-04 於 17:09 +0000,Matthew Garrett 提到:
> On Thu, Mar 04, 2010 at 10:07:53AM -0700, Joey Lee wrote:
> > Thank's for your review and suggestion.
> > Per discuss for msi-laptop patchset, I will submit a bit patch for the
> > following change:
> > 	- remove threeg sysfs interface.
> > 	- add KEY_RFKILL keymapping to msi-laptop.
> 
> If the key event comes through the keyboard controller, there's no need 
> to add the mapping to msi-laptop. Doing it through udev or hal is fine.
> 

Thank's fully undertood, now, will send patch for remove threeg sysfs
interface.


Joey Lee


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 58/62] msi-laptop: Support some MSI 3G netbook that is need load SCM
  2010-03-04 17:07 Joey Lee
@ 2010-03-04 17:09 ` Matthew Garrett
  0 siblings, 0 replies; 11+ messages in thread
From: Matthew Garrett @ 2010-03-04 17:09 UTC (permalink / raw)
  To: Joey Lee; +Cc: mzxreary, gregkh, linux-kernel

On Thu, Mar 04, 2010 at 10:07:53AM -0700, Joey Lee wrote:
> Thank's for your review and suggestion.
> Per discuss for msi-laptop patchset, I will submit a bit patch for the
> following change:
> 	- remove threeg sysfs interface.
> 	- add KEY_RFKILL keymapping to msi-laptop.

If the key event comes through the keyboard controller, there's no need 
to add the mapping to msi-laptop. Doing it through udev or hal is fine.

-- 
Matthew Garrett | mjg59@srcf.ucam.org

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 58/62] msi-laptop: Support some MSI 3G netbook that is need load SCM
@ 2010-03-04 17:07 Joey Lee
  2010-03-04 17:09 ` Matthew Garrett
  0 siblings, 1 reply; 11+ messages in thread
From: Joey Lee @ 2010-03-04 17:07 UTC (permalink / raw)
  To: mjg59; +Cc: mzxreary, gregkh, linux-kernel

Hi Matthew, 

於 三,2010-03-03 於 13:45 +0000,Matthew Garrett 提到:
> On Tue, Mar 02, 2010 at 09:52:12PM -0700, Joey Lee wrote:
> 
> > I developed this driver on 2.6.31 kernel, and I found this key code is
> > in 2.6.33 kernel and later.
> > There have one and only one scancode to control 3 devices when end user
> > press fn+f11 key on MSI N034.
> > Currently, we setup this mapping in HAL key and mapping it to KEY_WLAN.
> 
> Ah! The key comes through the keyboard controller? In that case, yeah, 
> just map it to KEY_RFKILL in hal isntead of KEY_WLAN. Everything should 
> work fine then. If rfkill-input is configured, it'll kill all the 
> radios. If userland claims it instead, it can cycle through with 
> whatever policy is desired.
> 

Thank's for your review and suggestion.
Per discuss for msi-laptop patchset, I will submit a bit patch for the
following change:
	- remove threeg sysfs interface.
	- add KEY_RFKILL keymapping to msi-laptop.

Does it make sense? or I still miss something important?


Thank's
Joey Lee


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 58/62] msi-laptop: Support some MSI 3G netbook that is need load SCM
  2010-03-02 23:39   ` Matthew Garrett
@ 2010-03-02 23:46     ` Greg KH
  0 siblings, 0 replies; 11+ messages in thread
From: Greg KH @ 2010-03-02 23:46 UTC (permalink / raw)
  To: Matthew Garrett; +Cc: linux-kernel, Lee, Chun-Yi, Lennart Poettering

On Tue, Mar 02, 2010 at 11:39:29PM +0000, Matthew Garrett wrote:
> On Tue, Mar 02, 2010 at 03:28:57PM -0800, Greg Kroah-Hartman wrote:
> > From: Lee, Chun-Yi <jlee@novell.com>
> > 
> > Some MSI 3G netbook only have one fn key to control Wlan/Bluetooth/3G,
> > those netbook will load the SCM (windows app) to disable the original
> > Wlan/Bluetooth control by BIOS when user press fn key, then control
> > Wlan/Bluetooth/3G by SCM (software control by OS). Without SCM, user
> > cann't on/off 3G module on those 3G netbook.
> > On Linux, msi-laptop driver will do the same thing to disable the
> > original BIOS control, then might need use HAL or other userland
> > application to do the software control that simulate with SCM.
> > e.g. MSI N034 netbook
> 
> How does the function key event get reported to userland? This should 
> generate KEY_RFKILL and then just go through rfkill-input.

I'm pretty sure that Joey is using rfkill here, but I didn't realize
that it also supported an input device.

This code is just detecting the keypress, and acting on it, I think,
right Joey?  Isn't that the way this is supposed to work?  Or is it
supposed to use rfkill-input, which then userspace turns around and
calls the other rfkill interface to then disable the wireless?  If so, I
think a number of laptop drivers need to be changed to do this.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 58/62] msi-laptop: Support some MSI 3G netbook that is need load SCM
  2010-03-02 23:28 ` [PATCH 58/62] msi-laptop: Support some MSI 3G netbook that is need load SCM Greg Kroah-Hartman
@ 2010-03-02 23:39   ` Matthew Garrett
  2010-03-02 23:46     ` Greg KH
  0 siblings, 1 reply; 11+ messages in thread
From: Matthew Garrett @ 2010-03-02 23:39 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-kernel, Lee, Chun-Yi, Lennart Poettering

On Tue, Mar 02, 2010 at 03:28:57PM -0800, Greg Kroah-Hartman wrote:
> From: Lee, Chun-Yi <jlee@novell.com>
> 
> Some MSI 3G netbook only have one fn key to control Wlan/Bluetooth/3G,
> those netbook will load the SCM (windows app) to disable the original
> Wlan/Bluetooth control by BIOS when user press fn key, then control
> Wlan/Bluetooth/3G by SCM (software control by OS). Without SCM, user
> cann't on/off 3G module on those 3G netbook.
> On Linux, msi-laptop driver will do the same thing to disable the
> original BIOS control, then might need use HAL or other userland
> application to do the software control that simulate with SCM.
> e.g. MSI N034 netbook

How does the function key event get reported to userland? This should 
generate KEY_RFKILL and then just go through rfkill-input.

-- 
Matthew Garrett | mjg59@srcf.ucam.org

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 58/62] msi-laptop: Support some MSI 3G netbook that is need load SCM
  2010-03-02 23:09 [GIT PATCH] driver core patches for 2.6.33-git Greg KH
@ 2010-03-02 23:28 ` Greg Kroah-Hartman
  2010-03-02 23:39   ` Matthew Garrett
  0 siblings, 1 reply; 11+ messages in thread
From: Greg Kroah-Hartman @ 2010-03-02 23:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: Lee, Chun-Yi, Lennart Poettering, Greg Kroah-Hartman

From: Lee, Chun-Yi <jlee@novell.com>

Some MSI 3G netbook only have one fn key to control Wlan/Bluetooth/3G,
those netbook will load the SCM (windows app) to disable the original
Wlan/Bluetooth control by BIOS when user press fn key, then control
Wlan/Bluetooth/3G by SCM (software control by OS). Without SCM, user
cann't on/off 3G module on those 3G netbook.
On Linux, msi-laptop driver will do the same thing to disable the
original BIOS control, then might need use HAL or other userland
application to do the software control that simulate with SCM.
e.g. MSI N034 netbook

Signed-off-by: Lee, Chun-Yi <jlee@novell.com>
Cc: Lennart Poettering <mzxreary@0pointer.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/platform/x86/msi-laptop.c |  238 +++++++++++++++++++++++++++++++++++++
 1 files changed, 238 insertions(+), 0 deletions(-)

diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
index 1784d55..ff21d1a 100644
--- a/drivers/platform/x86/msi-laptop.c
+++ b/drivers/platform/x86/msi-laptop.c
@@ -58,6 +58,7 @@
 #include <linux/dmi.h>
 #include <linux/backlight.h>
 #include <linux/platform_device.h>
+#include <linux/rfkill.h>
 
 #define MSI_DRIVER_VERSION "0.5"
 
@@ -72,6 +73,10 @@
 #define MSI_STANDARD_EC_WLAN_MASK	(1 << 3)
 #define MSI_STANDARD_EC_3G_MASK		(1 << 4)
 
+/* For set SCM load flag to disable BIOS fn key */
+#define MSI_STANDARD_EC_SCM_LOAD_ADDRESS	0x2d
+#define MSI_STANDARD_EC_SCM_LOAD_MASK		(1 << 0)
+
 static int force;
 module_param(force, bool, 0);
 MODULE_PARM_DESC(force, "Force driver load, ignore DMI data");
@@ -83,6 +88,19 @@ MODULE_PARM_DESC(auto_brightness, "Enable automatic brightness control (0: disab
 static bool old_ec_model;
 static int wlan_s, bluetooth_s, threeg_s;
 
+/* Some MSI 3G netbook only have one fn key to control Wlan/Bluetooth/3G,
+ * those netbook will load the SCM (windows app) to disable the original
+ * Wlan/Bluetooth control by BIOS when user press fn key, then control
+ * Wlan/Bluetooth/3G by SCM (software control by OS). Without SCM, user
+ * cann't on/off 3G module on those 3G netbook.
+ * On Linux, msi-laptop driver will do the same thing to disable the
+ * original BIOS control, then might need use HAL or other userland
+ * application to do the software control that simulate with SCM.
+ * e.g. MSI N034 netbook
+ */
+static bool load_scm_model;
+static struct rfkill *rfk_wlan, *rfk_bluetooth, *rfk_threeg;
+
 /* Hardware access */
 
 static int set_lcd_level(int level)
@@ -139,6 +157,35 @@ static int set_auto_brightness(int enable)
 	return ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, wdata, 2, NULL, 0, 1);
 }
 
+static ssize_t set_device_state(const char *buf, size_t count, u8 mask)
+{
+	int status;
+	u8 wdata = 0, rdata;
+	int result;
+
+	if (sscanf(buf, "%i", &status) != 1 || (status < 0 || status > 1))
+		return -EINVAL;
+
+	/* read current device state */
+	result = ec_read(MSI_STANDARD_EC_COMMAND_ADDRESS, &rdata);
+	if (result < 0)
+		return -EINVAL;
+
+	if (!!(rdata & mask) != status) {
+		/* reverse device bit */
+		if (rdata & mask)
+			wdata = rdata & ~mask;
+		else
+			wdata = rdata | mask;
+
+		result = ec_write(MSI_STANDARD_EC_COMMAND_ADDRESS, wdata);
+		if (result < 0)
+			return -EINVAL;
+	}
+
+	return count;
+}
+
 static int get_wireless_state(int *wlan, int *bluetooth)
 {
 	u8 wdata = 0, rdata;
@@ -215,6 +262,12 @@ static ssize_t show_wlan(struct device *dev,
 	return sprintf(buf, "%i\n", enabled);
 }
 
+static ssize_t store_wlan(struct device *dev,
+	struct device_attribute *attr, const char *buf, size_t count)
+{
+	return set_device_state(buf, count, MSI_STANDARD_EC_WLAN_MASK);
+}
+
 static ssize_t show_bluetooth(struct device *dev,
 	struct device_attribute *attr, char *buf)
 {
@@ -233,6 +286,12 @@ static ssize_t show_bluetooth(struct device *dev,
 	return sprintf(buf, "%i\n", enabled);
 }
 
+static ssize_t store_bluetooth(struct device *dev,
+	struct device_attribute *attr, const char *buf, size_t count)
+{
+	return set_device_state(buf, count, MSI_STANDARD_EC_BLUETOOTH_MASK);
+}
+
 static ssize_t show_threeg(struct device *dev,
 	struct device_attribute *attr, char *buf)
 {
@@ -250,6 +309,12 @@ static ssize_t show_threeg(struct device *dev,
 	return sprintf(buf, "%i\n", threeg_s);
 }
 
+static ssize_t store_threeg(struct device *dev,
+	struct device_attribute *attr, const char *buf, size_t count)
+{
+	return set_device_state(buf, count, MSI_STANDARD_EC_3G_MASK);
+}
+
 static ssize_t show_lcd_level(struct device *dev,
 	struct device_attribute *attr, char *buf)
 {
@@ -387,6 +452,169 @@ static struct dmi_system_id __initdata msi_dmi_table[] = {
 	{ }
 };
 
+static struct dmi_system_id __initdata msi_load_scm_models_dmi_table[] = {
+	{
+		.ident = "MSI N034",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR,
+				"MICRO-STAR INTERNATIONAL CO., LTD"),
+			DMI_MATCH(DMI_PRODUCT_NAME, "MS-N034"),
+			DMI_MATCH(DMI_CHASSIS_VENDOR,
+			"MICRO-STAR INTERNATIONAL CO., LTD")
+		},
+		.callback = dmi_check_cb
+	},
+	{ }
+};
+
+static int rfkill_bluetooth_set(void *data, bool blocked)
+{
+	/* Do something with blocked...*/
+	/*
+	 * blocked == false is on
+	 * blocked == true is off
+	 */
+	if (blocked)
+		set_device_state("0", 0, MSI_STANDARD_EC_BLUETOOTH_MASK);
+	else
+		set_device_state("1", 0, MSI_STANDARD_EC_BLUETOOTH_MASK);
+
+	return 0;
+}
+
+static int rfkill_wlan_set(void *data, bool blocked)
+{
+	if (blocked)
+		set_device_state("0", 0, MSI_STANDARD_EC_WLAN_MASK);
+	else
+		set_device_state("1", 0, MSI_STANDARD_EC_WLAN_MASK);
+
+	return 0;
+}
+
+static int rfkill_threeg_set(void *data, bool blocked)
+{
+	if (blocked)
+		set_device_state("0", 0, MSI_STANDARD_EC_3G_MASK);
+	else
+		set_device_state("1", 0, MSI_STANDARD_EC_3G_MASK);
+
+	return 0;
+}
+
+static struct rfkill_ops rfkill_bluetooth_ops = {
+	.set_block = rfkill_bluetooth_set
+};
+
+static struct rfkill_ops rfkill_wlan_ops = {
+	.set_block = rfkill_wlan_set
+};
+
+static struct rfkill_ops rfkill_threeg_ops = {
+	.set_block = rfkill_threeg_set
+};
+
+static void rfkill_cleanup(void)
+{
+	if (rfk_bluetooth) {
+		rfkill_unregister(rfk_bluetooth);
+		rfkill_destroy(rfk_bluetooth);
+	}
+
+	if (rfk_threeg) {
+		rfkill_unregister(rfk_threeg);
+		rfkill_destroy(rfk_threeg);
+	}
+
+	if (rfk_wlan) {
+		rfkill_unregister(rfk_wlan);
+		rfkill_destroy(rfk_wlan);
+	}
+}
+
+static int rfkill_init(struct platform_device *sdev)
+{
+	/* add rfkill */
+	int retval;
+
+	rfk_bluetooth = rfkill_alloc("msi-bluetooth", &sdev->dev,
+				RFKILL_TYPE_BLUETOOTH,
+				&rfkill_bluetooth_ops, NULL);
+	if (!rfk_bluetooth) {
+		retval = -ENOMEM;
+		goto err_bluetooth;
+	}
+	retval = rfkill_register(rfk_bluetooth);
+	if (retval)
+		goto err_bluetooth;
+
+	rfk_wlan = rfkill_alloc("msi-wlan", &sdev->dev, RFKILL_TYPE_WLAN,
+				&rfkill_wlan_ops, NULL);
+	if (!rfk_wlan) {
+		retval = -ENOMEM;
+		goto err_wlan;
+	}
+	retval = rfkill_register(rfk_wlan);
+	if (retval)
+		goto err_wlan;
+
+	rfk_threeg = rfkill_alloc("msi-threeg", &sdev->dev, RFKILL_TYPE_WWAN,
+				&rfkill_threeg_ops, NULL);
+	if (!rfk_threeg) {
+		retval = -ENOMEM;
+		goto err_threeg;
+	}
+	retval = rfkill_register(rfk_threeg);
+	if (retval)
+		goto err_threeg;
+
+	return 0;
+
+err_threeg:
+	rfkill_destroy(rfk_threeg);
+	if (rfk_wlan)
+		rfkill_unregister(rfk_wlan);
+err_wlan:
+	rfkill_destroy(rfk_wlan);
+	if (rfk_bluetooth)
+		rfkill_unregister(rfk_bluetooth);
+err_bluetooth:
+	rfkill_destroy(rfk_bluetooth);
+
+	return retval;
+}
+
+static int load_scm_model_init(struct platform_device *sdev)
+{
+	u8 data;
+	int result;
+
+	/* allow userland write sysfs file  */
+	dev_attr_bluetooth.store = store_bluetooth;
+	dev_attr_wlan.store = store_wlan;
+	dev_attr_threeg.store = store_threeg;
+	dev_attr_bluetooth.attr.mode |= S_IWUSR;
+	dev_attr_wlan.attr.mode |= S_IWUSR;
+	dev_attr_threeg.attr.mode |= S_IWUSR;
+
+	/* disable hardware control by fn key */
+	result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
+	if (result < 0)
+		return result;
+
+	result = ec_write(MSI_STANDARD_EC_SCM_LOAD_ADDRESS,
+		data | MSI_STANDARD_EC_SCM_LOAD_MASK);
+	if (result < 0)
+		return result;
+
+	/* initial rfkill */
+	result = rfkill_init(sdev);
+	if (result < 0)
+		return result;
+
+	return 0;
+}
+
 static int __init msi_init(void)
 {
 	int ret;
@@ -397,6 +625,9 @@ static int __init msi_init(void)
 	if (force || dmi_check_system(msi_dmi_table))
 		old_ec_model = 1;
 
+	if (!old_ec_model && dmi_check_system(msi_load_scm_models_dmi_table))
+		load_scm_model = 1;
+
 	if (auto_brightness < 0 || auto_brightness > 2)
 		return -EINVAL;
 
@@ -429,6 +660,11 @@ static int __init msi_init(void)
 	if (ret)
 		goto fail_platform_device1;
 
+	if (load_scm_model && (load_scm_model_init(msipf_device) < 0)) {
+		ret = -EINVAL;
+		goto fail_platform_device1;
+	}
+
 	ret = sysfs_create_group(&msipf_device->dev.kobj, &msipf_attribute_group);
 	if (ret)
 		goto fail_platform_device2;
@@ -479,6 +715,8 @@ static void __exit msi_cleanup(void)
 	platform_driver_unregister(&msipf_driver);
 	backlight_device_unregister(msibl_device);
 
+	rfkill_cleanup();
+
 	/* Enable automatic brightness control again */
 	if (auto_brightness != 2)
 		set_auto_brightness(1);
-- 
1.7.0.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-03-09 21:15 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-03  4:52 [PATCH 58/62] msi-laptop: Support some MSI 3G netbook that is need load SCM Joey Lee
2010-03-03 13:45 ` Matthew Garrett
  -- strict thread matches above, loose matches on Subject: below --
2010-03-09 12:42 Joey Lee
2010-03-09 21:01 ` Greg KH
2010-03-09 21:14   ` Matthew Garrett
2010-03-05  6:10 Joey Lee
2010-03-04 17:07 Joey Lee
2010-03-04 17:09 ` Matthew Garrett
2010-03-02 23:09 [GIT PATCH] driver core patches for 2.6.33-git Greg KH
2010-03-02 23:28 ` [PATCH 58/62] msi-laptop: Support some MSI 3G netbook that is need load SCM Greg Kroah-Hartman
2010-03-02 23:39   ` Matthew Garrett
2010-03-02 23:46     ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.