aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-input.c
diff options
context:
space:
mode:
authorJeremy Fitzhardinge <jeremy@goop.org>2011-12-02 22:05:07 -0500
committerJeremy Fitzhardinge <jeremy@goop.org>2012-01-08 02:30:38 -0500
commit2f2e3f6d7a24e7fceb0fef514767025cddb64dc2 (patch)
tree57acc61ecb41724002a77fcbcd2b9b67baec3094 /drivers/hid/hid-input.c
parentfb8ac91b4dccbdda0ad51d499079d05143783ba4 (diff)
hid-input/battery: make the battery setup common for INPUTs and FEATUREs
Signed-off-by: Jeremy Fitzhardinge <jeremy@goop.org>
Diffstat (limited to 'drivers/hid/hid-input.c')
-rw-r--r--drivers/hid/hid-input.c43
1 files changed, 20 insertions, 23 deletions
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index f5c3efcdcb0..771ff5df574 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -351,20 +351,22 @@ static int hidinput_get_battery_property(struct power_supply *psy,
351 return ret; 351 return ret;
352} 352}
353 353
354static void hidinput_setup_battery(struct hid_device *dev, 354static bool hidinput_setup_battery(struct hid_device *dev, unsigned report_type, struct hid_field *field)
355 unsigned report_type, unsigned report_id,
356 s32 min, s32 max)
357{ 355{
358 struct power_supply *battery = &dev->battery; 356 struct power_supply *battery = &dev->battery;
359 int ret; 357 int ret;
360 unsigned quirks; 358 unsigned quirks;
359 s32 min, max;
360
361 if (field->usage->hid != HID_DC_BATTERYSTRENGTH)
362 return false; /* no match */
361 363
362 if (battery->name != NULL) 364 if (battery->name != NULL)
363 return; /* already initialized? */ 365 goto out; /* already initialized? */
364 366
365 battery->name = kasprintf(GFP_KERNEL, "hid-%s-battery", dev->uniq); 367 battery->name = kasprintf(GFP_KERNEL, "hid-%s-battery", dev->uniq);
366 if (battery->name == NULL) 368 if (battery->name == NULL)
367 return; 369 goto out;
368 370
369 battery->type = POWER_SUPPLY_TYPE_USB; 371 battery->type = POWER_SUPPLY_TYPE_USB;
370 battery->properties = hidinput_battery_props; 372 battery->properties = hidinput_battery_props;
@@ -374,6 +376,9 @@ static void hidinput_setup_battery(struct hid_device *dev,
374 376
375 quirks = find_battery_quirk(dev); 377 quirks = find_battery_quirk(dev);
376 378
379 min = field->logical_minimum;
380 max = field->logical_maximum;
381
377 if (quirks & HID_BATTERY_QUIRK_PERCENT) { 382 if (quirks & HID_BATTERY_QUIRK_PERCENT) {
378 min = 0; 383 min = 0;
379 max = 100; 384 max = 100;
@@ -382,7 +387,7 @@ static void hidinput_setup_battery(struct hid_device *dev,
382 dev->battery_min = min; 387 dev->battery_min = min;
383 dev->battery_max = max; 388 dev->battery_max = max;
384 dev->battery_report_type = report_type; 389 dev->battery_report_type = report_type;
385 dev->battery_report_id = report_id; 390 dev->battery_report_id = field->report->id;
386 391
387 ret = power_supply_register(&dev->dev, battery); 392 ret = power_supply_register(&dev->dev, battery);
388 if (ret != 0) { 393 if (ret != 0) {
@@ -390,6 +395,9 @@ static void hidinput_setup_battery(struct hid_device *dev,
390 kfree(battery->name); 395 kfree(battery->name);
391 battery->name = NULL; 396 battery->name = NULL;
392 } 397 }
398
399out:
400 return true;
393} 401}
394 402
395static void hidinput_cleanup_battery(struct hid_device *dev) 403static void hidinput_cleanup_battery(struct hid_device *dev)
@@ -402,10 +410,10 @@ static void hidinput_cleanup_battery(struct hid_device *dev)
402 dev->battery.name = NULL; 410 dev->battery.name = NULL;
403} 411}
404#else /* !CONFIG_HID_BATTERY_STRENGTH */ 412#else /* !CONFIG_HID_BATTERY_STRENGTH */
405static void hidinput_setup_battery(struct hid_device *dev, 413static bool hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
406 unsigned report_type, unsigned report_id, 414 struct hid_field *field)
407 s32 min, s32 max)
408{ 415{
416 return false;
409} 417}
410 418
411static void hidinput_cleanup_battery(struct hid_device *dev) 419static void hidinput_cleanup_battery(struct hid_device *dev)
@@ -772,14 +780,9 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
772 break; 780 break;
773 781
774 case HID_UP_GENDEVCTRLS: 782 case HID_UP_GENDEVCTRLS:
775 if ((usage->hid & HID_USAGE) == 0x20) { /* Battery Strength */ 783 if (hidinput_setup_battery(device, HID_INPUT_REPORT, field))
776 hidinput_setup_battery(device,
777 HID_INPUT_REPORT,
778 field->report->id,
779 field->logical_minimum,
780 field->logical_maximum);
781 goto ignore; 784 goto ignore;
782 } else 785 else
783 goto unknown; 786 goto unknown;
784 break; 787 break;
785 788
@@ -1055,13 +1058,7 @@ static void report_features(struct hid_device *hid)
1055 for (i = 0; i < rep->maxfield; i++) 1058 for (i = 0; i < rep->maxfield; i++)
1056 for (j = 0; j < rep->field[i]->maxusage; j++) { 1059 for (j = 0; j < rep->field[i]->maxusage; j++) {
1057 /* Verify if Battery Strength feature is available */ 1060 /* Verify if Battery Strength feature is available */
1058 if (((rep->field[i]->usage + j)->hid & HID_USAGE_PAGE) == HID_UP_GENDEVCTRLS && 1061 hidinput_setup_battery(hid, HID_FEATURE_REPORT, rep->field[i]);
1059 ((rep->field[i]->usage + j)->hid & HID_USAGE) == 0x20) {
1060 hidinput_setup_battery(hid,
1061 HID_FEATURE_REPORT, rep->id,
1062 rep->field[i]->logical_minimum,
1063 rep->field[i]->logical_maximum);
1064 }
1065 1062
1066 if (drv->feature_mapping) 1063 if (drv->feature_mapping)
1067 drv->feature_mapping(hid, rep->field[i], 1064 drv->feature_mapping(hid, rep->field[i],