19c92ab61SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2176aa360SChanwoo Choi /*
3176aa360SChanwoo Choi  * External Connector (extcon) framework
4176aa360SChanwoo Choi  * - linux/include/linux/extcon-provider.h for extcon provider device driver.
5176aa360SChanwoo Choi  *
6176aa360SChanwoo Choi  * Copyright (C) 2017 Samsung Electronics
7176aa360SChanwoo Choi  * Author: Chanwoo Choi <cw00.choi@samsung.com>
8176aa360SChanwoo Choi  */
9176aa360SChanwoo Choi 
10176aa360SChanwoo Choi #ifndef __LINUX_EXTCON_PROVIDER_H__
11176aa360SChanwoo Choi #define __LINUX_EXTCON_PROVIDER_H__
12176aa360SChanwoo Choi 
13176aa360SChanwoo Choi #include <linux/extcon.h>
14176aa360SChanwoo Choi 
15176aa360SChanwoo Choi struct extcon_dev;
16176aa360SChanwoo Choi 
17176aa360SChanwoo Choi #if IS_ENABLED(CONFIG_EXTCON)
18176aa360SChanwoo Choi 
19176aa360SChanwoo Choi /* Following APIs register/unregister the extcon device. */
20b52cc1bbSChanwoo Choi int extcon_dev_register(struct extcon_dev *edev);
21b52cc1bbSChanwoo Choi void extcon_dev_unregister(struct extcon_dev *edev);
22b52cc1bbSChanwoo Choi int devm_extcon_dev_register(struct device *dev,
23176aa360SChanwoo Choi 				struct extcon_dev *edev);
24b52cc1bbSChanwoo Choi void devm_extcon_dev_unregister(struct device *dev,
25176aa360SChanwoo Choi 				struct extcon_dev *edev);
26176aa360SChanwoo Choi 
27176aa360SChanwoo Choi /* Following APIs allocate/free the memory of the extcon device. */
28b52cc1bbSChanwoo Choi struct extcon_dev *extcon_dev_allocate(const unsigned int *cable);
29b52cc1bbSChanwoo Choi void extcon_dev_free(struct extcon_dev *edev);
30b52cc1bbSChanwoo Choi struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
31176aa360SChanwoo Choi 				const unsigned int *cable);
32b52cc1bbSChanwoo Choi void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev);
33176aa360SChanwoo Choi 
34176aa360SChanwoo Choi /* Synchronize the state and property value for each external connector. */
35b52cc1bbSChanwoo Choi int extcon_sync(struct extcon_dev *edev, unsigned int id);
36176aa360SChanwoo Choi 
37176aa360SChanwoo Choi /*
38176aa360SChanwoo Choi  * Following APIs set the connected state of each external connector.
39176aa360SChanwoo Choi  * The 'id' argument indicates the defined external connector.
40176aa360SChanwoo Choi  */
41b52cc1bbSChanwoo Choi int extcon_set_state(struct extcon_dev *edev, unsigned int id,
42176aa360SChanwoo Choi 				bool state);
43b52cc1bbSChanwoo Choi int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id,
44176aa360SChanwoo Choi 				bool state);
45176aa360SChanwoo Choi 
46176aa360SChanwoo Choi /*
47176aa360SChanwoo Choi  * Following APIs set the property of each external connector.
48176aa360SChanwoo Choi  * The 'id' argument indicates the defined external connector
49176aa360SChanwoo Choi  * and the 'prop' indicates the extcon property.
50176aa360SChanwoo Choi  *
51176aa360SChanwoo Choi  * And extcon_set_property_capability() set the capability of the property
52176aa360SChanwoo Choi  * for each external connector. They are used to set the capability of the
53176aa360SChanwoo Choi  * property of each external connector based on the id and property.
54176aa360SChanwoo Choi  */
55b52cc1bbSChanwoo Choi int extcon_set_property(struct extcon_dev *edev, unsigned int id,
56176aa360SChanwoo Choi 				unsigned int prop,
57176aa360SChanwoo Choi 				union extcon_property_value prop_val);
58b52cc1bbSChanwoo Choi int extcon_set_property_sync(struct extcon_dev *edev, unsigned int id,
59176aa360SChanwoo Choi 				unsigned int prop,
60176aa360SChanwoo Choi 				union extcon_property_value prop_val);
61b52cc1bbSChanwoo Choi int extcon_set_property_capability(struct extcon_dev *edev,
62176aa360SChanwoo Choi 				unsigned int id, unsigned int prop);
63176aa360SChanwoo Choi 
64176aa360SChanwoo Choi #else /* CONFIG_EXTCON */
extcon_dev_register(struct extcon_dev * edev)65176aa360SChanwoo Choi static inline int extcon_dev_register(struct extcon_dev *edev)
66176aa360SChanwoo Choi {
67176aa360SChanwoo Choi 	return 0;
68176aa360SChanwoo Choi }
69176aa360SChanwoo Choi 
extcon_dev_unregister(struct extcon_dev * edev)70176aa360SChanwoo Choi static inline void extcon_dev_unregister(struct extcon_dev *edev) { }
71176aa360SChanwoo Choi 
devm_extcon_dev_register(struct device * dev,struct extcon_dev * edev)72176aa360SChanwoo Choi static inline int devm_extcon_dev_register(struct device *dev,
73176aa360SChanwoo Choi 				struct extcon_dev *edev)
74176aa360SChanwoo Choi {
75176aa360SChanwoo Choi 	return -EINVAL;
76176aa360SChanwoo Choi }
77176aa360SChanwoo Choi 
devm_extcon_dev_unregister(struct device * dev,struct extcon_dev * edev)78176aa360SChanwoo Choi static inline void devm_extcon_dev_unregister(struct device *dev,
79176aa360SChanwoo Choi 				struct extcon_dev *edev) { }
80176aa360SChanwoo Choi 
extcon_dev_allocate(const unsigned int * cable)81176aa360SChanwoo Choi static inline struct extcon_dev *extcon_dev_allocate(const unsigned int *cable)
82176aa360SChanwoo Choi {
83176aa360SChanwoo Choi 	return ERR_PTR(-ENOSYS);
84176aa360SChanwoo Choi }
85176aa360SChanwoo Choi 
extcon_dev_free(struct extcon_dev * edev)86176aa360SChanwoo Choi static inline void extcon_dev_free(struct extcon_dev *edev) { }
87176aa360SChanwoo Choi 
devm_extcon_dev_allocate(struct device * dev,const unsigned int * cable)88176aa360SChanwoo Choi static inline struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
89176aa360SChanwoo Choi 				const unsigned int *cable)
90176aa360SChanwoo Choi {
91176aa360SChanwoo Choi 	return ERR_PTR(-ENOSYS);
92176aa360SChanwoo Choi }
93176aa360SChanwoo Choi 
devm_extcon_dev_free(struct extcon_dev * edev)94176aa360SChanwoo Choi static inline void devm_extcon_dev_free(struct extcon_dev *edev) { }
95176aa360SChanwoo Choi 
96176aa360SChanwoo Choi 
extcon_set_state(struct extcon_dev * edev,unsigned int id,bool state)97176aa360SChanwoo Choi static inline int extcon_set_state(struct extcon_dev *edev, unsigned int id,
98176aa360SChanwoo Choi 				bool state)
99176aa360SChanwoo Choi {
100176aa360SChanwoo Choi 	return 0;
101176aa360SChanwoo Choi }
102176aa360SChanwoo Choi 
extcon_set_state_sync(struct extcon_dev * edev,unsigned int id,bool state)103176aa360SChanwoo Choi static inline int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id,
104176aa360SChanwoo Choi 				bool state)
105176aa360SChanwoo Choi {
106176aa360SChanwoo Choi 	return 0;
107176aa360SChanwoo Choi }
108176aa360SChanwoo Choi 
extcon_sync(struct extcon_dev * edev,unsigned int id)109176aa360SChanwoo Choi static inline int extcon_sync(struct extcon_dev *edev, unsigned int id)
110176aa360SChanwoo Choi {
111176aa360SChanwoo Choi 	return 0;
112176aa360SChanwoo Choi }
113176aa360SChanwoo Choi 
extcon_set_property(struct extcon_dev * edev,unsigned int id,unsigned int prop,union extcon_property_value prop_val)114176aa360SChanwoo Choi static inline int extcon_set_property(struct extcon_dev *edev, unsigned int id,
115176aa360SChanwoo Choi 				unsigned int prop,
116176aa360SChanwoo Choi 				union extcon_property_value prop_val)
117176aa360SChanwoo Choi {
118176aa360SChanwoo Choi 	return 0;
119176aa360SChanwoo Choi }
120176aa360SChanwoo Choi 
extcon_set_property_sync(struct extcon_dev * edev,unsigned int id,unsigned int prop,union extcon_property_value prop_val)121176aa360SChanwoo Choi static inline int extcon_set_property_sync(struct extcon_dev *edev,
122176aa360SChanwoo Choi 				unsigned int id, unsigned int prop,
123176aa360SChanwoo Choi 				union extcon_property_value prop_val)
124176aa360SChanwoo Choi {
125176aa360SChanwoo Choi 	return 0;
126176aa360SChanwoo Choi }
127176aa360SChanwoo Choi 
extcon_set_property_capability(struct extcon_dev * edev,unsigned int id,unsigned int prop)128176aa360SChanwoo Choi static inline int extcon_set_property_capability(struct extcon_dev *edev,
129176aa360SChanwoo Choi 				unsigned int id, unsigned int prop)
130176aa360SChanwoo Choi {
131176aa360SChanwoo Choi 	return 0;
132176aa360SChanwoo Choi }
133176aa360SChanwoo Choi #endif /* CONFIG_EXTCON */
134176aa360SChanwoo Choi #endif /* __LINUX_EXTCON_PROVIDER_H__ */
135