summaryrefslogtreecommitdiff
path: root/drivers/hid/hid-gearvr.c
blob: 09e6459b0c4fdd997ebcf8a7082a2a940b364151 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
 * Author: Andi Shyti <andi.shyti@samsung.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * Samsung Gear VR device driver
 */

#include <linux/hidraw.h>
#include <linux/module.h>

#include "hid-ids.h"

static int gearvr_probe(struct hid_device *hdev, const struct hid_device_id *id)
{
	int err;

	err = hid_parse(hdev);
	if (err)
		return err;

	err = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
	if (err)
		return err;

	err = hid_hw_power(hdev, PM_HINT_FULLON);
	if (err < 0)
		goto fail_dev_stop;

	err = hid_hw_open(hdev);
	if (err < 0)
		goto fail_power_off;

	return 0;

fail_power_off:
	hid_hw_power(hdev, PM_HINT_NORMAL);
fail_dev_stop:
	hid_hw_stop(hdev);

	return err;
}

static void gearvr_remove(struct hid_device *hdev)
{
	hid_hw_close(hdev);
	hid_hw_power(hdev, PM_HINT_NORMAL);
	hid_hw_stop(hdev);
}

static const struct hid_device_id gearvr_devices[] = {
	{ HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG_ELECTRONICS,
			USB_DEVICE_ID_SAMSUNG_GEARVR_R320) },
	{ }
};

MODULE_DEVICE_TABLE(hid, gearvr_devices);

static struct hid_driver gearvr_driver = {
	.name = "gearvr",
	.id_table = gearvr_devices,
	.probe = gearvr_probe,
	.remove = gearvr_remove,
};

module_hid_driver(gearvr_driver);

MODULE_AUTHOR("Andi Shyti <andi.shyti@samsung.com>");
MODULE_DESCRIPTION("Samsung Gear VR device driver");
MODULE_LICENSE("GPL v2");