aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-sensor-hub.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hid/hid-sensor-hub.c')
-rw-r--r--drivers/hid/hid-sensor-hub.c45
1 files changed, 35 insertions, 10 deletions
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index 9e4cdca549c0..a184e1921c11 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -468,6 +468,39 @@ static int sensor_hub_raw_event(struct hid_device *hdev,
468 return 1; 468 return 1;
469} 469}
470 470
471int sensor_hub_device_open(struct hid_sensor_hub_device *hsdev)
472{
473 int ret = 0;
474 struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
475
476 mutex_lock(&data->mutex);
477 if (!hsdev->ref_cnt) {
478 ret = hid_hw_open(hsdev->hdev);
479 if (ret) {
480 hid_err(hsdev->hdev, "failed to open hid device\n");
481 mutex_unlock(&data->mutex);
482 return ret;
483 }
484 }
485 hsdev->ref_cnt++;
486 mutex_unlock(&data->mutex);
487
488 return ret;
489}
490EXPORT_SYMBOL_GPL(sensor_hub_device_open);
491
492void sensor_hub_device_close(struct hid_sensor_hub_device *hsdev)
493{
494 struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
495
496 mutex_lock(&data->mutex);
497 hsdev->ref_cnt--;
498 if (!hsdev->ref_cnt)
499 hid_hw_close(hsdev->hdev);
500 mutex_unlock(&data->mutex);
501}
502EXPORT_SYMBOL_GPL(sensor_hub_device_close);
503
471static int sensor_hub_probe(struct hid_device *hdev, 504static int sensor_hub_probe(struct hid_device *hdev,
472 const struct hid_device_id *id) 505 const struct hid_device_id *id)
473{ 506{
@@ -509,12 +542,6 @@ static int sensor_hub_probe(struct hid_device *hdev,
509 hid_err(hdev, "hw start failed\n"); 542 hid_err(hdev, "hw start failed\n");
510 return ret; 543 return ret;
511 } 544 }
512 ret = hid_hw_open(hdev);
513 if (ret) {
514 hid_err(hdev, "failed to open input interrupt pipe\n");
515 goto err_stop_hw;
516 }
517
518 INIT_LIST_HEAD(&sd->dyn_callback_list); 545 INIT_LIST_HEAD(&sd->dyn_callback_list);
519 sd->hid_sensor_client_cnt = 0; 546 sd->hid_sensor_client_cnt = 0;
520 report_enum = &hdev->report_enum[HID_INPUT_REPORT]; 547 report_enum = &hdev->report_enum[HID_INPUT_REPORT];
@@ -523,7 +550,7 @@ static int sensor_hub_probe(struct hid_device *hdev,
523 if (dev_cnt > HID_MAX_PHY_DEVICES) { 550 if (dev_cnt > HID_MAX_PHY_DEVICES) {
524 hid_err(hdev, "Invalid Physical device count\n"); 551 hid_err(hdev, "Invalid Physical device count\n");
525 ret = -EINVAL; 552 ret = -EINVAL;
526 goto err_close; 553 goto err_stop_hw;
527 } 554 }
528 sd->hid_sensor_hub_client_devs = kzalloc(dev_cnt * 555 sd->hid_sensor_hub_client_devs = kzalloc(dev_cnt *
529 sizeof(struct mfd_cell), 556 sizeof(struct mfd_cell),
@@ -531,7 +558,7 @@ static int sensor_hub_probe(struct hid_device *hdev,
531 if (sd->hid_sensor_hub_client_devs == NULL) { 558 if (sd->hid_sensor_hub_client_devs == NULL) {
532 hid_err(hdev, "Failed to allocate memory for mfd cells\n"); 559 hid_err(hdev, "Failed to allocate memory for mfd cells\n");
533 ret = -ENOMEM; 560 ret = -ENOMEM;
534 goto err_close; 561 goto err_stop_hw;
535 } 562 }
536 list_for_each_entry(report, &report_enum->report_list, list) { 563 list_for_each_entry(report, &report_enum->report_list, list) {
537 hid_dbg(hdev, "Report id:%x\n", report->id); 564 hid_dbg(hdev, "Report id:%x\n", report->id);
@@ -568,8 +595,6 @@ err_free_names:
568 for (i = 0; i < sd->hid_sensor_client_cnt ; ++i) 595 for (i = 0; i < sd->hid_sensor_client_cnt ; ++i)
569 kfree(sd->hid_sensor_hub_client_devs[i].name); 596 kfree(sd->hid_sensor_hub_client_devs[i].name);
570 kfree(sd->hid_sensor_hub_client_devs); 597 kfree(sd->hid_sensor_hub_client_devs);
571err_close:
572 hid_hw_close(hdev);
573err_stop_hw: 598err_stop_hw:
574 hid_hw_stop(hdev); 599 hid_hw_stop(hdev);
575 600