summaryrefstree
path: root/kernel/drivers/input/misc/hall/hall_ic_notifier.c
blob: eb39ca7a8f167e4c22966a952d94b66c3670ce0d (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
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (C) 2019 Samsung Electronics
 */

#if IS_ENABLED(CONFIG_HALL_NOTIFIER)
#include <linux/hall/hall_ic_notifier.h>
#endif

#if IS_ENABLED(CONFIG_HALL_NOTIFIER)
static struct hall_notifier_context hall_notifier;
static struct blocking_notifier_head hall_nb_head = BLOCKING_NOTIFIER_INIT(hall_nb_head);

int hall_notifier_register(struct notifier_block *n)
{
	int ret = 0;

	pr_info("%s\n", __func__);

	ret = blocking_notifier_chain_register(&hall_nb_head, n);
	if (ret < 0)
		pr_err("%s: failed(%d)\n", __func__, ret);

	return ret;
}
EXPORT_SYMBOL_GPL(hall_notifier_register);

int hall_notifier_unregister(struct notifier_block *nb)
{
	int ret = 0;

	pr_info("%s\n", __func__);

	ret = blocking_notifier_chain_unregister(&hall_nb_head, nb);
	if (ret < 0)
		pr_err("%s: failed(%d)\n", __func__, ret);

	return ret;
}
EXPORT_SYMBOL_GPL(hall_notifier_unregister);

int hall_notifier_notify(const char *hall_name, int hall_value)
{
	int ret = 0;

	pr_info("%s: name: %s value: %d\n", __func__, hall_name, hall_value);

	hall_notifier.name = hall_name;
	hall_notifier.value = hall_value;

	ret = blocking_notifier_call_chain(&hall_nb_head, hall_value, &hall_notifier);

	switch (ret) {
	case NOTIFY_DONE:
	case NOTIFY_OK:
		pr_info("%s done(0x%x)\n", __func__, ret);
		break;
	default:
		pr_info("%s failed(0x%x)\n", __func__, ret);
		break;
	}

	return ret;
}
EXPORT_SYMBOL_GPL(hall_notifier_notify);
#endif /* if IS_ENABLED(CONFIG_HALL_NOTIFIER) */