blob: 7ef9184f29bd8bd037fe350dec5830b5f8078bf9 (
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
74
75
76
77
78
79
80
81
|
/*
* Copyright (C) 2016 Motorola Mobility, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/notifier.h>
#include <linux/mods/usb_ext_bridge.h>
static DEFINE_MUTEX(usb_ext_mutex);
static BLOCKING_NOTIFIER_HEAD(usb_ext_notifier_list);
static struct usb_ext_status usb_ext_current_status;
/*
* Add caller to receive notifications of changes in attach state.
*/
int usb_ext_register_notifier(struct notifier_block *nb,
usb_ext_cb cb)
{
int ret = blocking_notifier_chain_register(&usb_ext_notifier_list, nb);
if (cb && !ret) {
struct usb_ext_status st;
mutex_lock(&usb_ext_mutex);
st = usb_ext_current_status;
mutex_unlock(&usb_ext_mutex);
cb(&st);
}
return ret;
}
EXPORT_SYMBOL(usb_ext_register_notifier);
/*
* Remove caller from receiving notifications of changes in attach state
*/
int usb_ext_unregister_notifier(struct notifier_block *nb)
{
return blocking_notifier_chain_unregister(&usb_ext_notifier_list, nb);
}
EXPORT_SYMBOL(usb_ext_unregister_notifier);
/*
* Get the current attach state for the USB-EXT interface
*/
void usb_ext_get_state(struct usb_ext_status *status)
{
mutex_lock(&usb_ext_mutex);
*status = usb_ext_current_status;
mutex_unlock(&usb_ext_mutex);
}
EXPORT_SYMBOL(usb_ext_get_state);
/*
* Set the current attach state for the USB-EXT interface
*/
void usb_ext_set_state(const struct usb_ext_status *status)
{
struct usb_ext_status st;
mutex_lock(&usb_ext_mutex);
usb_ext_current_status = *status;
st = *status;
mutex_unlock(&usb_ext_mutex);
blocking_notifier_call_chain(&usb_ext_notifier_list, st.active, &st);
}
EXPORT_SYMBOL(usb_ext_set_state);
|