Commit c1f73658 authored by Ike Panhc's avatar Ike Panhc Committed by Matthew Garrett

ideapad: pass ideapad_priv as argument (part 2)

Passing ideapad_priv as argument and try not to using too much global variable.
This is part 2 for rfkill.
Signed-off-by: default avatarIke Panhc <ike.pan@canonical.com>
Signed-off-by: default avatarMatthew Garrett <mjg@redhat.com>
parent 8693ae84
...@@ -31,32 +31,15 @@ ...@@ -31,32 +31,15 @@
#include <linux/input.h> #include <linux/input.h>
#include <linux/input/sparse-keymap.h> #include <linux/input/sparse-keymap.h>
#define IDEAPAD_DEV_CAMERA 0 #define IDEAPAD_RFKILL_DEV_NUM (3)
#define IDEAPAD_DEV_WLAN 1
#define IDEAPAD_DEV_BLUETOOTH 2
#define IDEAPAD_DEV_3G 3
#define IDEAPAD_DEV_KILLSW 4
struct ideapad_private { struct ideapad_private {
acpi_handle handle; struct rfkill *rfk[IDEAPAD_RFKILL_DEV_NUM];
struct rfkill *rfk[5];
struct platform_device *platform_device; struct platform_device *platform_device;
struct input_dev *inputdev; struct input_dev *inputdev;
} *ideapad_priv;
static struct {
char *name;
int cfgbit;
int opcode;
int type;
} ideapad_rfk_data[] = {
{ "ideapad_camera", 19, 0x1E, NUM_RFKILL_TYPES },
{ "ideapad_wlan", 18, 0x15, RFKILL_TYPE_WLAN },
{ "ideapad_bluetooth", 16, 0x17, RFKILL_TYPE_BLUETOOTH },
{ "ideapad_3g", 17, 0x20, RFKILL_TYPE_WWAN },
{ "ideapad_killsw", 0, 0, RFKILL_TYPE_WLAN }
}; };
static acpi_handle ideapad_handle;
static bool no_bt_rfkill; static bool no_bt_rfkill;
module_param(no_bt_rfkill, bool, 0444); module_param(no_bt_rfkill, bool, 0444);
MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth."); MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth.");
...@@ -176,11 +159,9 @@ static ssize_t show_ideapad_cam(struct device *dev, ...@@ -176,11 +159,9 @@ static ssize_t show_ideapad_cam(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct ideapad_private *priv = dev_get_drvdata(dev);
acpi_handle handle = priv->handle;
unsigned long result; unsigned long result;
if (read_ec_data(handle, 0x1D, &result)) if (read_ec_data(ideapad_handle, 0x1D, &result))
return sprintf(buf, "-1\n"); return sprintf(buf, "-1\n");
return sprintf(buf, "%lu\n", result); return sprintf(buf, "%lu\n", result);
} }
...@@ -189,15 +170,13 @@ static ssize_t store_ideapad_cam(struct device *dev, ...@@ -189,15 +170,13 @@ static ssize_t store_ideapad_cam(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct ideapad_private *priv = dev_get_drvdata(dev);
acpi_handle handle = priv->handle;
int ret, state; int ret, state;
if (!count) if (!count)
return 0; return 0;
if (sscanf(buf, "%i", &state) != 1) if (sscanf(buf, "%i", &state) != 1)
return -EINVAL; return -EINVAL;
ret = write_ec_cmd(handle, 0x1E, state); ret = write_ec_cmd(ideapad_handle, 0x1E, state);
if (ret < 0) if (ret < 0)
return ret; return ret;
return count; return count;
...@@ -208,16 +187,24 @@ static DEVICE_ATTR(camera_power, 0644, show_ideapad_cam, store_ideapad_cam); ...@@ -208,16 +187,24 @@ static DEVICE_ATTR(camera_power, 0644, show_ideapad_cam, store_ideapad_cam);
/* /*
* Rfkill * Rfkill
*/ */
struct ideapad_rfk_data {
char *name;
int cfgbit;
int opcode;
int type;
};
const struct ideapad_rfk_data ideapad_rfk_data[] = {
{ "ideapad_wlan", 18, 0x15, RFKILL_TYPE_WLAN },
{ "ideapad_bluetooth", 16, 0x17, RFKILL_TYPE_BLUETOOTH },
{ "ideapad_3g", 17, 0x20, RFKILL_TYPE_WWAN },
};
static int ideapad_rfk_set(void *data, bool blocked) static int ideapad_rfk_set(void *data, bool blocked)
{ {
int device = (unsigned long)data; unsigned long opcode = (unsigned long)data;
if (device == IDEAPAD_DEV_KILLSW) return write_ec_cmd(ideapad_handle, opcode, !blocked);
return -EINVAL;
return write_ec_cmd(ideapad_priv->handle,
ideapad_rfk_data[device].opcode,
!blocked);
} }
static struct rfkill_ops ideapad_rfk_ops = { static struct rfkill_ops ideapad_rfk_ops = {
...@@ -227,15 +214,14 @@ static struct rfkill_ops ideapad_rfk_ops = { ...@@ -227,15 +214,14 @@ static struct rfkill_ops ideapad_rfk_ops = {
static void ideapad_sync_rfk_state(struct acpi_device *adevice) static void ideapad_sync_rfk_state(struct acpi_device *adevice)
{ {
struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); struct ideapad_private *priv = dev_get_drvdata(&adevice->dev);
acpi_handle handle = priv->handle;
unsigned long hw_blocked; unsigned long hw_blocked;
int i; int i;
if (read_ec_data(handle, 0x23, &hw_blocked)) if (read_ec_data(ideapad_handle, 0x23, &hw_blocked))
return; return;
hw_blocked = !hw_blocked; hw_blocked = !hw_blocked;
for (i = IDEAPAD_DEV_WLAN; i <= IDEAPAD_DEV_KILLSW; i++) for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
if (priv->rfk[i]) if (priv->rfk[i])
rfkill_set_hw_state(priv->rfk[i], hw_blocked); rfkill_set_hw_state(priv->rfk[i], hw_blocked);
} }
...@@ -250,7 +236,7 @@ static int __devinit ideapad_register_rfkill(struct acpi_device *adevice, ...@@ -250,7 +236,7 @@ static int __devinit ideapad_register_rfkill(struct acpi_device *adevice,
if (no_bt_rfkill && if (no_bt_rfkill &&
(ideapad_rfk_data[dev].type == RFKILL_TYPE_BLUETOOTH)) { (ideapad_rfk_data[dev].type == RFKILL_TYPE_BLUETOOTH)) {
/* Force to enable bluetooth when no_bt_rfkill=1 */ /* Force to enable bluetooth when no_bt_rfkill=1 */
write_ec_cmd(ideapad_priv->handle, write_ec_cmd(ideapad_handle,
ideapad_rfk_data[dev].opcode, 1); ideapad_rfk_data[dev].opcode, 1);
return 0; return 0;
} }
...@@ -261,7 +247,7 @@ static int __devinit ideapad_register_rfkill(struct acpi_device *adevice, ...@@ -261,7 +247,7 @@ static int __devinit ideapad_register_rfkill(struct acpi_device *adevice,
if (!priv->rfk[dev]) if (!priv->rfk[dev])
return -ENOMEM; return -ENOMEM;
if (read_ec_data(ideapad_priv->handle, ideapad_rfk_data[dev].opcode-1, if (read_ec_data(ideapad_handle, ideapad_rfk_data[dev].opcode-1,
&sw_blocked)) { &sw_blocked)) {
rfkill_init_sw_state(priv->rfk[dev], 0); rfkill_init_sw_state(priv->rfk[dev], 0);
} else { } else {
...@@ -414,9 +400,8 @@ static int __devinit ideapad_acpi_add(struct acpi_device *adevice) ...@@ -414,9 +400,8 @@ static int __devinit ideapad_acpi_add(struct acpi_device *adevice)
priv = kzalloc(sizeof(*priv), GFP_KERNEL); priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
ideapad_priv = priv;
priv->handle = adevice->handle;
dev_set_drvdata(&adevice->dev, priv); dev_set_drvdata(&adevice->dev, priv);
ideapad_handle = adevice->handle;
ret = ideapad_platform_init(priv); ret = ideapad_platform_init(priv);
if (ret) if (ret)
...@@ -426,9 +411,11 @@ static int __devinit ideapad_acpi_add(struct acpi_device *adevice) ...@@ -426,9 +411,11 @@ static int __devinit ideapad_acpi_add(struct acpi_device *adevice)
if (ret) if (ret)
goto input_failed; goto input_failed;
for (i = IDEAPAD_DEV_WLAN; i < IDEAPAD_DEV_KILLSW; i++) { for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) {
if (test_bit(ideapad_rfk_data[i].cfgbit, (unsigned long *)&cfg)) if (test_bit(ideapad_rfk_data[i].cfgbit, (unsigned long *)&cfg))
ideapad_register_rfkill(adevice, i); ideapad_register_rfkill(adevice, i);
else
priv->rfk[i] = NULL;
} }
ideapad_sync_rfk_state(adevice); ideapad_sync_rfk_state(adevice);
...@@ -446,7 +433,7 @@ static int __devexit ideapad_acpi_remove(struct acpi_device *adevice, int type) ...@@ -446,7 +433,7 @@ static int __devexit ideapad_acpi_remove(struct acpi_device *adevice, int type)
struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); struct ideapad_private *priv = dev_get_drvdata(&adevice->dev);
int i; int i;
for (i = IDEAPAD_DEV_WLAN; i < IDEAPAD_DEV_KILLSW; i++) for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
ideapad_unregister_rfkill(adevice, i); ideapad_unregister_rfkill(adevice, i);
ideapad_input_exit(priv); ideapad_input_exit(priv);
ideapad_platform_exit(priv); ideapad_platform_exit(priv);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment