blob: c9c9afe12b47db837034cedf2d41012fe81730f8 [file] [log] [blame]
MyungJoo Hamde55d872012-04-20 14:16:22 +09001/*
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
Donggeun Kim74c5d092012-04-20 14:16:24 +090026#include <linux/notifier.h>
MyungJoo Hamde55d872012-04-20 14:16:22 +090027/**
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
Donggeun Kim74c5d092012-04-20 14:16:24 +090038 * @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.
MyungJoo Hamde55d872012-04-20 14:16:22 +090041 *
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 */
47struct 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;
Donggeun Kim74c5d092012-04-20 14:16:24 +090058 struct raw_notifier_head nh;
59 struct list_head entry;
MyungJoo Hamde55d872012-04-20 14:16:22 +090060};
61
62#if IS_ENABLED(CONFIG_EXTCON)
Donggeun Kim74c5d092012-04-20 14:16:24 +090063
64/*
65 * Following APIs are for notifiers or configurations.
66 * Notifiers are the external port and connection devices.
67 */
MyungJoo Hamde55d872012-04-20 14:16:22 +090068extern int extcon_dev_register(struct extcon_dev *edev, struct device *dev);
69extern void extcon_dev_unregister(struct extcon_dev *edev);
Donggeun Kim74c5d092012-04-20 14:16:24 +090070extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name);
MyungJoo Hamde55d872012-04-20 14:16:22 +090071
72static inline u32 extcon_get_state(struct extcon_dev *edev)
73{
74 return edev->state;
75}
76
77extern void extcon_set_state(struct extcon_dev *edev, u32 state);
Donggeun Kim74c5d092012-04-20 14:16:24 +090078
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 */
83extern int extcon_register_notifier(struct extcon_dev *edev,
84 struct notifier_block *nb);
85extern int extcon_unregister_notifier(struct extcon_dev *edev,
86 struct notifier_block *nb);
MyungJoo Hamde55d872012-04-20 14:16:22 +090087#else /* CONFIG_EXTCON */
88static inline int extcon_dev_register(struct extcon_dev *edev,
89 struct device *dev)
90{
91 return 0;
92}
93
94static inline void extcon_dev_unregister(struct extcon_dev *edev) { }
95
96static inline u32 extcon_get_state(struct extcon_dev *edev)
97{
98 return 0;
99}
100
101static inline void extcon_set_state(struct extcon_dev *edev, u32 state) { }
Donggeun Kim74c5d092012-04-20 14:16:24 +0900102static inline struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
103{
104 return NULL;
105}
106
107static inline int extcon_register_notifier(struct extcon_dev *edev,
108 struct notifier_block *nb)
109{
110 return 0;
111}
112
113static inline int extcon_unregister_notifier(struct extcon_dev *edev,
114 struct notifier_block *nb)
115{
116 return 0;
117}
118
MyungJoo Hamde55d872012-04-20 14:16:22 +0900119#endif /* CONFIG_EXTCON */
120#endif /* __LINUX_EXTCON_H__ */