xref: /OK3568_Linux_fs/kernel/include/linux/extcon-provider.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * External Connector (extcon) framework
4*4882a593Smuzhiyun  * - linux/include/linux/extcon-provider.h for extcon provider device driver.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Copyright (C) 2017 Samsung Electronics
7*4882a593Smuzhiyun  * Author: Chanwoo Choi <cw00.choi@samsung.com>
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #ifndef __LINUX_EXTCON_PROVIDER_H__
11*4882a593Smuzhiyun #define __LINUX_EXTCON_PROVIDER_H__
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #include <linux/extcon.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun struct extcon_dev;
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_EXTCON)
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun /* Following APIs register/unregister the extcon device. */
20*4882a593Smuzhiyun int extcon_dev_register(struct extcon_dev *edev);
21*4882a593Smuzhiyun void extcon_dev_unregister(struct extcon_dev *edev);
22*4882a593Smuzhiyun int devm_extcon_dev_register(struct device *dev,
23*4882a593Smuzhiyun 				struct extcon_dev *edev);
24*4882a593Smuzhiyun void devm_extcon_dev_unregister(struct device *dev,
25*4882a593Smuzhiyun 				struct extcon_dev *edev);
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun /* Following APIs allocate/free the memory of the extcon device. */
28*4882a593Smuzhiyun struct extcon_dev *extcon_dev_allocate(const unsigned int *cable);
29*4882a593Smuzhiyun void extcon_dev_free(struct extcon_dev *edev);
30*4882a593Smuzhiyun struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
31*4882a593Smuzhiyun 				const unsigned int *cable);
32*4882a593Smuzhiyun void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev);
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun /* Synchronize the state and property value for each external connector. */
35*4882a593Smuzhiyun int extcon_sync(struct extcon_dev *edev, unsigned int id);
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun /*
38*4882a593Smuzhiyun  * Following APIs set the connected state of each external connector.
39*4882a593Smuzhiyun  * The 'id' argument indicates the defined external connector.
40*4882a593Smuzhiyun  */
41*4882a593Smuzhiyun int extcon_set_state(struct extcon_dev *edev, unsigned int id,
42*4882a593Smuzhiyun 				bool state);
43*4882a593Smuzhiyun int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id,
44*4882a593Smuzhiyun 				bool state);
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun /*
47*4882a593Smuzhiyun  * Following APIs set the property of each external connector.
48*4882a593Smuzhiyun  * The 'id' argument indicates the defined external connector
49*4882a593Smuzhiyun  * and the 'prop' indicates the extcon property.
50*4882a593Smuzhiyun  *
51*4882a593Smuzhiyun  * And extcon_set_property_capability() set the capability of the property
52*4882a593Smuzhiyun  * for each external connector. They are used to set the capability of the
53*4882a593Smuzhiyun  * property of each external connector based on the id and property.
54*4882a593Smuzhiyun  */
55*4882a593Smuzhiyun int extcon_set_property(struct extcon_dev *edev, unsigned int id,
56*4882a593Smuzhiyun 				unsigned int prop,
57*4882a593Smuzhiyun 				union extcon_property_value prop_val);
58*4882a593Smuzhiyun int extcon_set_property_sync(struct extcon_dev *edev, unsigned int id,
59*4882a593Smuzhiyun 				unsigned int prop,
60*4882a593Smuzhiyun 				union extcon_property_value prop_val);
61*4882a593Smuzhiyun int extcon_set_property_capability(struct extcon_dev *edev,
62*4882a593Smuzhiyun 				unsigned int id, unsigned int prop);
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun #else /* CONFIG_EXTCON */
extcon_dev_register(struct extcon_dev * edev)65*4882a593Smuzhiyun static inline int extcon_dev_register(struct extcon_dev *edev)
66*4882a593Smuzhiyun {
67*4882a593Smuzhiyun 	return 0;
68*4882a593Smuzhiyun }
69*4882a593Smuzhiyun 
extcon_dev_unregister(struct extcon_dev * edev)70*4882a593Smuzhiyun static inline void extcon_dev_unregister(struct extcon_dev *edev) { }
71*4882a593Smuzhiyun 
devm_extcon_dev_register(struct device * dev,struct extcon_dev * edev)72*4882a593Smuzhiyun static inline int devm_extcon_dev_register(struct device *dev,
73*4882a593Smuzhiyun 				struct extcon_dev *edev)
74*4882a593Smuzhiyun {
75*4882a593Smuzhiyun 	return -EINVAL;
76*4882a593Smuzhiyun }
77*4882a593Smuzhiyun 
devm_extcon_dev_unregister(struct device * dev,struct extcon_dev * edev)78*4882a593Smuzhiyun static inline void devm_extcon_dev_unregister(struct device *dev,
79*4882a593Smuzhiyun 				struct extcon_dev *edev) { }
80*4882a593Smuzhiyun 
extcon_dev_allocate(const unsigned int * cable)81*4882a593Smuzhiyun static inline struct extcon_dev *extcon_dev_allocate(const unsigned int *cable)
82*4882a593Smuzhiyun {
83*4882a593Smuzhiyun 	return ERR_PTR(-ENOSYS);
84*4882a593Smuzhiyun }
85*4882a593Smuzhiyun 
extcon_dev_free(struct extcon_dev * edev)86*4882a593Smuzhiyun static inline void extcon_dev_free(struct extcon_dev *edev) { }
87*4882a593Smuzhiyun 
devm_extcon_dev_allocate(struct device * dev,const unsigned int * cable)88*4882a593Smuzhiyun static inline struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
89*4882a593Smuzhiyun 				const unsigned int *cable)
90*4882a593Smuzhiyun {
91*4882a593Smuzhiyun 	return ERR_PTR(-ENOSYS);
92*4882a593Smuzhiyun }
93*4882a593Smuzhiyun 
devm_extcon_dev_free(struct extcon_dev * edev)94*4882a593Smuzhiyun static inline void devm_extcon_dev_free(struct extcon_dev *edev) { }
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun 
extcon_set_state(struct extcon_dev * edev,unsigned int id,bool state)97*4882a593Smuzhiyun static inline int extcon_set_state(struct extcon_dev *edev, unsigned int id,
98*4882a593Smuzhiyun 				bool state)
99*4882a593Smuzhiyun {
100*4882a593Smuzhiyun 	return 0;
101*4882a593Smuzhiyun }
102*4882a593Smuzhiyun 
extcon_set_state_sync(struct extcon_dev * edev,unsigned int id,bool state)103*4882a593Smuzhiyun static inline int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id,
104*4882a593Smuzhiyun 				bool state)
105*4882a593Smuzhiyun {
106*4882a593Smuzhiyun 	return 0;
107*4882a593Smuzhiyun }
108*4882a593Smuzhiyun 
extcon_sync(struct extcon_dev * edev,unsigned int id)109*4882a593Smuzhiyun static inline int extcon_sync(struct extcon_dev *edev, unsigned int id)
110*4882a593Smuzhiyun {
111*4882a593Smuzhiyun 	return 0;
112*4882a593Smuzhiyun }
113*4882a593Smuzhiyun 
extcon_set_property(struct extcon_dev * edev,unsigned int id,unsigned int prop,union extcon_property_value prop_val)114*4882a593Smuzhiyun static inline int extcon_set_property(struct extcon_dev *edev, unsigned int id,
115*4882a593Smuzhiyun 				unsigned int prop,
116*4882a593Smuzhiyun 				union extcon_property_value prop_val)
117*4882a593Smuzhiyun {
118*4882a593Smuzhiyun 	return 0;
119*4882a593Smuzhiyun }
120*4882a593Smuzhiyun 
extcon_set_property_sync(struct extcon_dev * edev,unsigned int id,unsigned int prop,union extcon_property_value prop_val)121*4882a593Smuzhiyun static inline int extcon_set_property_sync(struct extcon_dev *edev,
122*4882a593Smuzhiyun 				unsigned int id, unsigned int prop,
123*4882a593Smuzhiyun 				union extcon_property_value prop_val)
124*4882a593Smuzhiyun {
125*4882a593Smuzhiyun 	return 0;
126*4882a593Smuzhiyun }
127*4882a593Smuzhiyun 
extcon_set_property_capability(struct extcon_dev * edev,unsigned int id,unsigned int prop)128*4882a593Smuzhiyun static inline int extcon_set_property_capability(struct extcon_dev *edev,
129*4882a593Smuzhiyun 				unsigned int id, unsigned int prop)
130*4882a593Smuzhiyun {
131*4882a593Smuzhiyun 	return 0;
132*4882a593Smuzhiyun }
133*4882a593Smuzhiyun #endif /* CONFIG_EXTCON */
134*4882a593Smuzhiyun #endif /* __LINUX_EXTCON_PROVIDER_H__ */
135