Commit | Line | Data |
---|---|---|
de55d871 MH |
1 | /* |
2 | * External connector (extcon) class driver | |
3 | * | |
4 | * Copyright (C) 2012 Samsung Electronics | |
5 | * Author: Donggeun Kim <dg77.kim@samsung.com> | |
6 | * Author: MyungJoo Ham <myungjoo.ham@samsung.com> | |
7 | * | |
8 | * based on switch class driver | |
9 | * Copyright (C) 2008 Google, Inc. | |
10 | * Author: Mike Lockwood <lockwood@android.com> | |
11 | * | |
12 | * This software is licensed under the terms of the GNU General Public | |
13 | * License version 2, as published by the Free Software Foundation, and | |
14 | * may be copied, distributed, and modified under those terms. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | * GNU General Public License for more details. | |
20 | * | |
21 | */ | |
22 | ||
23 | #ifndef __LINUX_EXTCON_H__ | |
24 | #define __LINUX_EXTCON_H__ | |
25 | ||
74c5d09b | 26 | #include <linux/notifier.h> |
de55d871 MH |
27 | /** |
28 | * struct extcon_dev - An extcon device represents one external connector. | |
29 | * @name The name of this extcon device. Parent device name is used | |
30 | * if NULL. | |
31 | * @print_name An optional callback to override the method to print the | |
32 | * name of the extcon device. | |
33 | * @print_state An optional callback to override the method to print the | |
34 | * status of the extcon device. | |
35 | * @dev Device of this extcon. Do not provide at register-time. | |
36 | * @state Attach/detach state of this extcon. Do not provide at | |
37 | * register-time | |
74c5d09b DK |
38 | * @nh Notifier for the state change events from this extcon |
39 | * @entry To support list of extcon devices so that uses can search | |
40 | * for extcon devices based on the extcon name. | |
de55d871 MH |
41 | * |
42 | * In most cases, users only need to provide "User initializing data" of | |
43 | * this struct when registering an extcon. In some exceptional cases, | |
44 | * optional callbacks may be needed. However, the values in "internal data" | |
45 | * are overwritten by register function. | |
46 | */ | |
47 | struct extcon_dev { | |
48 | /* --- Optional user initializing data --- */ | |
49 | const char *name; | |
50 | ||
51 | /* --- Optional callbacks to override class functions --- */ | |
52 | ssize_t (*print_name)(struct extcon_dev *edev, char *buf); | |
53 | ssize_t (*print_state)(struct extcon_dev *edev, char *buf); | |
54 | ||
55 | /* --- Internal data. Please do not set. --- */ | |
56 | struct device *dev; | |
57 | u32 state; | |
74c5d09b DK |
58 | struct raw_notifier_head nh; |
59 | struct list_head entry; | |
de55d871 MH |
60 | }; |
61 | ||
62 | #if IS_ENABLED(CONFIG_EXTCON) | |
74c5d09b DK |
63 | |
64 | /* | |
65 | * Following APIs are for notifiers or configurations. | |
66 | * Notifiers are the external port and connection devices. | |
67 | */ | |
de55d871 MH |
68 | extern int extcon_dev_register(struct extcon_dev *edev, struct device *dev); |
69 | extern void extcon_dev_unregister(struct extcon_dev *edev); | |
74c5d09b | 70 | extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name); |
de55d871 MH |
71 | |
72 | static inline u32 extcon_get_state(struct extcon_dev *edev) | |
73 | { | |
74 | return edev->state; | |
75 | } | |
76 | ||
77 | extern void extcon_set_state(struct extcon_dev *edev, u32 state); | |
74c5d09b DK |
78 | |
79 | /* | |
80 | * Following APIs are to monitor every action of a notifier. | |
81 | * Registerer gets notified for every external port of a connection device. | |
82 | */ | |
83 | extern int extcon_register_notifier(struct extcon_dev *edev, | |
84 | struct notifier_block *nb); | |
85 | extern int extcon_unregister_notifier(struct extcon_dev *edev, | |
86 | struct notifier_block *nb); | |
de55d871 MH |
87 | #else /* CONFIG_EXTCON */ |
88 | static inline int extcon_dev_register(struct extcon_dev *edev, | |
89 | struct device *dev) | |
90 | { | |
91 | return 0; | |
92 | } | |
93 | ||
94 | static inline void extcon_dev_unregister(struct extcon_dev *edev) { } | |
95 | ||
96 | static inline u32 extcon_get_state(struct extcon_dev *edev) | |
97 | { | |
98 | return 0; | |
99 | } | |
100 | ||
101 | static inline void extcon_set_state(struct extcon_dev *edev, u32 state) { } | |
74c5d09b DK |
102 | static inline struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name) |
103 | { | |
104 | return NULL; | |
105 | } | |
106 | ||
107 | static inline int extcon_register_notifier(struct extcon_dev *edev, | |
108 | struct notifier_block *nb) | |
109 | { | |
110 | return 0; | |
111 | } | |
112 | ||
113 | static inline int extcon_unregister_notifier(struct extcon_dev *edev, | |
114 | struct notifier_block *nb) | |
115 | { | |
116 | return 0; | |
117 | } | |
118 | ||
de55d871 MH |
119 | #endif /* CONFIG_EXTCON */ |
120 | #endif /* __LINUX_EXTCON_H__ */ |