Skip to content

Commit c1f7365

Browse files
ikepanhcMatthew Garrett
authored andcommitted
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: Ike Panhc <[email protected]> Signed-off-by: Matthew Garrett <[email protected]>
1 parent 8693ae8 commit c1f7365

File tree

1 file changed

+29
-42
lines changed

1 file changed

+29
-42
lines changed

drivers/platform/x86/ideapad-laptop.c

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,15 @@
3131
#include <linux/input.h>
3232
#include <linux/input/sparse-keymap.h>
3333

34-
#define IDEAPAD_DEV_CAMERA 0
35-
#define IDEAPAD_DEV_WLAN 1
36-
#define IDEAPAD_DEV_BLUETOOTH 2
37-
#define IDEAPAD_DEV_3G 3
38-
#define IDEAPAD_DEV_KILLSW 4
34+
#define IDEAPAD_RFKILL_DEV_NUM (3)
3935

4036
struct ideapad_private {
41-
acpi_handle handle;
42-
struct rfkill *rfk[5];
37+
struct rfkill *rfk[IDEAPAD_RFKILL_DEV_NUM];
4338
struct platform_device *platform_device;
4439
struct input_dev *inputdev;
45-
} *ideapad_priv;
46-
47-
static struct {
48-
char *name;
49-
int cfgbit;
50-
int opcode;
51-
int type;
52-
} ideapad_rfk_data[] = {
53-
{ "ideapad_camera", 19, 0x1E, NUM_RFKILL_TYPES },
54-
{ "ideapad_wlan", 18, 0x15, RFKILL_TYPE_WLAN },
55-
{ "ideapad_bluetooth", 16, 0x17, RFKILL_TYPE_BLUETOOTH },
56-
{ "ideapad_3g", 17, 0x20, RFKILL_TYPE_WWAN },
57-
{ "ideapad_killsw", 0, 0, RFKILL_TYPE_WLAN }
5840
};
5941

42+
static acpi_handle ideapad_handle;
6043
static bool no_bt_rfkill;
6144
module_param(no_bt_rfkill, bool, 0444);
6245
MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth.");
@@ -176,11 +159,9 @@ static ssize_t show_ideapad_cam(struct device *dev,
176159
struct device_attribute *attr,
177160
char *buf)
178161
{
179-
struct ideapad_private *priv = dev_get_drvdata(dev);
180-
acpi_handle handle = priv->handle;
181162
unsigned long result;
182163

183-
if (read_ec_data(handle, 0x1D, &result))
164+
if (read_ec_data(ideapad_handle, 0x1D, &result))
184165
return sprintf(buf, "-1\n");
185166
return sprintf(buf, "%lu\n", result);
186167
}
@@ -189,15 +170,13 @@ static ssize_t store_ideapad_cam(struct device *dev,
189170
struct device_attribute *attr,
190171
const char *buf, size_t count)
191172
{
192-
struct ideapad_private *priv = dev_get_drvdata(dev);
193-
acpi_handle handle = priv->handle;
194173
int ret, state;
195174

196175
if (!count)
197176
return 0;
198177
if (sscanf(buf, "%i", &state) != 1)
199178
return -EINVAL;
200-
ret = write_ec_cmd(handle, 0x1E, state);
179+
ret = write_ec_cmd(ideapad_handle, 0x1E, state);
201180
if (ret < 0)
202181
return ret;
203182
return count;
@@ -208,16 +187,24 @@ static DEVICE_ATTR(camera_power, 0644, show_ideapad_cam, store_ideapad_cam);
208187
/*
209188
* Rfkill
210189
*/
190+
struct ideapad_rfk_data {
191+
char *name;
192+
int cfgbit;
193+
int opcode;
194+
int type;
195+
};
196+
197+
const struct ideapad_rfk_data ideapad_rfk_data[] = {
198+
{ "ideapad_wlan", 18, 0x15, RFKILL_TYPE_WLAN },
199+
{ "ideapad_bluetooth", 16, 0x17, RFKILL_TYPE_BLUETOOTH },
200+
{ "ideapad_3g", 17, 0x20, RFKILL_TYPE_WWAN },
201+
};
202+
211203
static int ideapad_rfk_set(void *data, bool blocked)
212204
{
213-
int device = (unsigned long)data;
214-
215-
if (device == IDEAPAD_DEV_KILLSW)
216-
return -EINVAL;
205+
unsigned long opcode = (unsigned long)data;
217206

218-
return write_ec_cmd(ideapad_priv->handle,
219-
ideapad_rfk_data[device].opcode,
220-
!blocked);
207+
return write_ec_cmd(ideapad_handle, opcode, !blocked);
221208
}
222209

223210
static struct rfkill_ops ideapad_rfk_ops = {
@@ -227,15 +214,14 @@ static struct rfkill_ops ideapad_rfk_ops = {
227214
static void ideapad_sync_rfk_state(struct acpi_device *adevice)
228215
{
229216
struct ideapad_private *priv = dev_get_drvdata(&adevice->dev);
230-
acpi_handle handle = priv->handle;
231217
unsigned long hw_blocked;
232218
int i;
233219

234-
if (read_ec_data(handle, 0x23, &hw_blocked))
220+
if (read_ec_data(ideapad_handle, 0x23, &hw_blocked))
235221
return;
236222
hw_blocked = !hw_blocked;
237223

238-
for (i = IDEAPAD_DEV_WLAN; i <= IDEAPAD_DEV_KILLSW; i++)
224+
for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
239225
if (priv->rfk[i])
240226
rfkill_set_hw_state(priv->rfk[i], hw_blocked);
241227
}
@@ -250,7 +236,7 @@ static int __devinit ideapad_register_rfkill(struct acpi_device *adevice,
250236
if (no_bt_rfkill &&
251237
(ideapad_rfk_data[dev].type == RFKILL_TYPE_BLUETOOTH)) {
252238
/* Force to enable bluetooth when no_bt_rfkill=1 */
253-
write_ec_cmd(ideapad_priv->handle,
239+
write_ec_cmd(ideapad_handle,
254240
ideapad_rfk_data[dev].opcode, 1);
255241
return 0;
256242
}
@@ -261,7 +247,7 @@ static int __devinit ideapad_register_rfkill(struct acpi_device *adevice,
261247
if (!priv->rfk[dev])
262248
return -ENOMEM;
263249

264-
if (read_ec_data(ideapad_priv->handle, ideapad_rfk_data[dev].opcode-1,
250+
if (read_ec_data(ideapad_handle, ideapad_rfk_data[dev].opcode-1,
265251
&sw_blocked)) {
266252
rfkill_init_sw_state(priv->rfk[dev], 0);
267253
} else {
@@ -414,9 +400,8 @@ static int __devinit ideapad_acpi_add(struct acpi_device *adevice)
414400
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
415401
if (!priv)
416402
return -ENOMEM;
417-
ideapad_priv = priv;
418-
priv->handle = adevice->handle;
419403
dev_set_drvdata(&adevice->dev, priv);
404+
ideapad_handle = adevice->handle;
420405

421406
ret = ideapad_platform_init(priv);
422407
if (ret)
@@ -426,9 +411,11 @@ static int __devinit ideapad_acpi_add(struct acpi_device *adevice)
426411
if (ret)
427412
goto input_failed;
428413

429-
for (i = IDEAPAD_DEV_WLAN; i < IDEAPAD_DEV_KILLSW; i++) {
414+
for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) {
430415
if (test_bit(ideapad_rfk_data[i].cfgbit, (unsigned long *)&cfg))
431416
ideapad_register_rfkill(adevice, i);
417+
else
418+
priv->rfk[i] = NULL;
432419
}
433420
ideapad_sync_rfk_state(adevice);
434421

@@ -446,7 +433,7 @@ static int __devexit ideapad_acpi_remove(struct acpi_device *adevice, int type)
446433
struct ideapad_private *priv = dev_get_drvdata(&adevice->dev);
447434
int i;
448435

449-
for (i = IDEAPAD_DEV_WLAN; i < IDEAPAD_DEV_KILLSW; i++)
436+
for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
450437
ideapad_unregister_rfkill(adevice, i);
451438
ideapad_input_exit(priv);
452439
ideapad_platform_exit(priv);

0 commit comments

Comments
 (0)