Skip to content

Commit 2be1dc2

Browse files
ikepanhcMatthew Garrett
authored andcommitted
ideapad: define vpc commands
Better then write hex number everywhere. Signed-off-by: Ike Panhc <ike.pan@canonical.com> Signed-off-by: Matthew Garrett <mjg@redhat.com>
1 parent 21893ab commit 2be1dc2

1 file changed

Lines changed: 41 additions & 16 deletions

File tree

‎drivers/platform/x86/ideapad-laptop.c‎

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,30 @@
4242
#define CFG_WIFI_BIT (18)
4343
#define CFG_CAMERA_BIT (19)
4444

45+
enum {
46+
VPCCMD_R_VPC1 = 0x10,
47+
VPCCMD_R_BL_MAX,
48+
VPCCMD_R_BL,
49+
VPCCMD_W_BL,
50+
VPCCMD_R_WIFI,
51+
VPCCMD_W_WIFI,
52+
VPCCMD_R_BT,
53+
VPCCMD_W_BT,
54+
VPCCMD_R_BL_POWER,
55+
VPCCMD_R_NOVO,
56+
VPCCMD_R_VPC2,
57+
VPCCMD_R_TOUCHPAD,
58+
VPCCMD_W_TOUCHPAD,
59+
VPCCMD_R_CAMERA,
60+
VPCCMD_W_CAMERA,
61+
VPCCMD_R_3G,
62+
VPCCMD_W_3G,
63+
VPCCMD_R_ODD, /* 0x21 */
64+
VPCCMD_R_RF = 0x23,
65+
VPCCMD_W_RF,
66+
VPCCMD_W_BL_POWER = 0x33,
67+
};
68+
4569
struct ideapad_private {
4670
struct rfkill *rfk[IDEAPAD_RFKILL_DEV_NUM];
4771
struct platform_device *platform_device;
@@ -172,7 +196,7 @@ static ssize_t show_ideapad_cam(struct device *dev,
172196
{
173197
unsigned long result;
174198

175-
if (read_ec_data(ideapad_handle, 0x1D, &result))
199+
if (read_ec_data(ideapad_handle, VPCCMD_R_CAMERA, &result))
176200
return sprintf(buf, "-1\n");
177201
return sprintf(buf, "%lu\n", result);
178202
}
@@ -187,7 +211,7 @@ static ssize_t store_ideapad_cam(struct device *dev,
187211
return 0;
188212
if (sscanf(buf, "%i", &state) != 1)
189213
return -EINVAL;
190-
ret = write_ec_cmd(ideapad_handle, 0x1E, state);
214+
ret = write_ec_cmd(ideapad_handle, VPCCMD_W_CAMERA, state);
191215
if (ret < 0)
192216
return ret;
193217
return count;
@@ -244,9 +268,9 @@ struct ideapad_rfk_data {
244268
};
245269

246270
const struct ideapad_rfk_data ideapad_rfk_data[] = {
247-
{ "ideapad_wlan", CFG_WIFI_BIT, 0x15, RFKILL_TYPE_WLAN },
248-
{ "ideapad_bluetooth", CFG_BT_BIT, 0x17, RFKILL_TYPE_BLUETOOTH },
249-
{ "ideapad_3g", CFG_3G_BIT, 0x20, RFKILL_TYPE_WWAN },
271+
{ "ideapad_wlan", CFG_WIFI_BIT, VPCCMD_W_WIFI, RFKILL_TYPE_WLAN },
272+
{ "ideapad_bluetooth", CFG_BT_BIT, VPCCMD_W_BT, RFKILL_TYPE_BLUETOOTH },
273+
{ "ideapad_3g", CFG_3G_BIT, VPCCMD_W_3G, RFKILL_TYPE_WWAN },
250274
};
251275

252276
static int ideapad_rfk_set(void *data, bool blocked)
@@ -266,7 +290,7 @@ static void ideapad_sync_rfk_state(struct acpi_device *adevice)
266290
unsigned long hw_blocked;
267291
int i;
268292

269-
if (read_ec_data(ideapad_handle, 0x23, &hw_blocked))
293+
if (read_ec_data(ideapad_handle, VPCCMD_R_RF, &hw_blocked))
270294
return;
271295
hw_blocked = !hw_blocked;
272296

@@ -426,16 +450,17 @@ static int ideapad_backlight_get_brightness(struct backlight_device *blightdev)
426450
{
427451
unsigned long now;
428452

429-
if (read_ec_data(ideapad_handle, 0x12, &now))
453+
if (read_ec_data(ideapad_handle, VPCCMD_R_BL, &now))
430454
return -EIO;
431455
return now;
432456
}
433457

434458
static int ideapad_backlight_update_status(struct backlight_device *blightdev)
435459
{
436-
if (write_ec_cmd(ideapad_handle, 0x13, blightdev->props.brightness))
460+
if (write_ec_cmd(ideapad_handle, VPCCMD_W_BL,
461+
blightdev->props.brightness))
437462
return -EIO;
438-
if (write_ec_cmd(ideapad_handle, 0x33,
463+
if (write_ec_cmd(ideapad_handle, VPCCMD_W_BL_POWER,
439464
blightdev->props.power == FB_BLANK_POWERDOWN ? 0 : 1))
440465
return -EIO;
441466

@@ -453,11 +478,11 @@ static int ideapad_backlight_init(struct ideapad_private *priv)
453478
struct backlight_properties props;
454479
unsigned long max, now, power;
455480

456-
if (read_ec_data(ideapad_handle, 0x11, &max))
481+
if (read_ec_data(ideapad_handle, VPCCMD_R_BL_MAX, &max))
457482
return -EIO;
458-
if (read_ec_data(ideapad_handle, 0x12, &now))
483+
if (read_ec_data(ideapad_handle, VPCCMD_R_BL, &now))
459484
return -EIO;
460-
if (read_ec_data(ideapad_handle, 0x18, &power))
485+
if (read_ec_data(ideapad_handle, VPCCMD_R_BL_POWER, &power))
461486
return -EIO;
462487

463488
memset(&props, 0, sizeof(struct backlight_properties));
@@ -495,7 +520,7 @@ static void ideapad_backlight_notify_power(struct ideapad_private *priv)
495520

496521
if (!blightdev)
497522
return;
498-
if (read_ec_data(ideapad_handle, 0x18, &power))
523+
if (read_ec_data(ideapad_handle, VPCCMD_R_BL_POWER, &power))
499524
return;
500525
blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
501526
}
@@ -506,7 +531,7 @@ static void ideapad_backlight_notify_brightness(struct ideapad_private *priv)
506531

507532
/* if we control brightness via acpi video driver */
508533
if (priv->blightdev == NULL) {
509-
read_ec_data(ideapad_handle, 0x12, &now);
534+
read_ec_data(ideapad_handle, VPCCMD_R_BL, &now);
510535
return;
511536
}
512537

@@ -595,9 +620,9 @@ static void ideapad_acpi_notify(struct acpi_device *adevice, u32 event)
595620
acpi_handle handle = adevice->handle;
596621
unsigned long vpc1, vpc2, vpc_bit;
597622

598-
if (read_ec_data(handle, 0x10, &vpc1))
623+
if (read_ec_data(handle, VPCCMD_R_VPC1, &vpc1))
599624
return;
600-
if (read_ec_data(handle, 0x1A, &vpc2))
625+
if (read_ec_data(handle, VPCCMD_R_VPC2, &vpc2))
601626
return;
602627

603628
vpc1 = (vpc2 << 8) | vpc1;

0 commit comments

Comments
 (0)