Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * External Connector (extcon) framework
0004  * - linux/include/linux/extcon.h for extcon consumer device driver.
0005  *
0006  * Copyright (C) 2015 Samsung Electronics
0007  * Author: Chanwoo Choi <cw00.choi@samsung.com>
0008  *
0009  * Copyright (C) 2012 Samsung Electronics
0010  * Author: Donggeun Kim <dg77.kim@samsung.com>
0011  * Author: MyungJoo Ham <myungjoo.ham@samsung.com>
0012  *
0013  * based on switch class driver
0014  * Copyright (C) 2008 Google, Inc.
0015  * Author: Mike Lockwood <lockwood@android.com>
0016  */
0017 
0018 #ifndef __LINUX_EXTCON_H__
0019 #define __LINUX_EXTCON_H__
0020 
0021 #include <linux/device.h>
0022 
0023 /*
0024  * Define the type of supported external connectors
0025  */
0026 #define EXTCON_TYPE_USB     BIT(0)  /* USB connector */
0027 #define EXTCON_TYPE_CHG     BIT(1)  /* Charger connector */
0028 #define EXTCON_TYPE_JACK    BIT(2)  /* Jack connector */
0029 #define EXTCON_TYPE_DISP    BIT(3)  /* Display connector */
0030 #define EXTCON_TYPE_MISC    BIT(4)  /* Miscellaneous connector */
0031 
0032 /*
0033  * Define the unique id of supported external connectors
0034  */
0035 #define EXTCON_NONE     0
0036 
0037 /* USB external connector */
0038 #define EXTCON_USB      1
0039 #define EXTCON_USB_HOST     2
0040 
0041 /*
0042  * Charging external connector
0043  *
0044  * When one SDP charger connector was reported, we should also report
0045  * the USB connector, which means EXTCON_CHG_USB_SDP should always
0046  * appear together with EXTCON_USB. The same as ACA charger connector,
0047  * EXTCON_CHG_USB_ACA would normally appear with EXTCON_USB_HOST.
0048  *
0049  * The EXTCON_CHG_USB_SLOW connector can provide at least 500mA of
0050  * current at 5V. The EXTCON_CHG_USB_FAST connector can provide at
0051  * least 1A of current at 5V.
0052  */
0053 #define EXTCON_CHG_USB_SDP  5   /* Standard Downstream Port */
0054 #define EXTCON_CHG_USB_DCP  6   /* Dedicated Charging Port */
0055 #define EXTCON_CHG_USB_CDP  7   /* Charging Downstream Port */
0056 #define EXTCON_CHG_USB_ACA  8   /* Accessory Charger Adapter */
0057 #define EXTCON_CHG_USB_FAST 9
0058 #define EXTCON_CHG_USB_SLOW 10
0059 #define EXTCON_CHG_WPT      11  /* Wireless Power Transfer */
0060 #define EXTCON_CHG_USB_PD   12  /* USB Power Delivery */
0061 
0062 /* Jack external connector */
0063 #define EXTCON_JACK_MICROPHONE  20
0064 #define EXTCON_JACK_HEADPHONE   21
0065 #define EXTCON_JACK_LINE_IN 22
0066 #define EXTCON_JACK_LINE_OUT    23
0067 #define EXTCON_JACK_VIDEO_IN    24
0068 #define EXTCON_JACK_VIDEO_OUT   25
0069 #define EXTCON_JACK_SPDIF_IN    26  /* Sony Philips Digital InterFace */
0070 #define EXTCON_JACK_SPDIF_OUT   27
0071 
0072 /* Display external connector */
0073 #define EXTCON_DISP_HDMI    40  /* High-Definition Multimedia Interface */
0074 #define EXTCON_DISP_MHL     41  /* Mobile High-Definition Link */
0075 #define EXTCON_DISP_DVI     42  /* Digital Visual Interface */
0076 #define EXTCON_DISP_VGA     43  /* Video Graphics Array */
0077 #define EXTCON_DISP_DP      44  /* Display Port */
0078 #define EXTCON_DISP_HMD     45  /* Head-Mounted Display */
0079 #define EXTCON_DISP_CVBS    46  /* Composite Video Broadcast Signal */
0080 #define EXTCON_DISP_EDP     47  /* Embedded Display Port */
0081 
0082 /* Miscellaneous external connector */
0083 #define EXTCON_DOCK     60
0084 #define EXTCON_JIG      61
0085 #define EXTCON_MECHANICAL   62
0086 
0087 #define EXTCON_NUM      63
0088 
0089 /*
0090  * Define the properties of supported external connectors.
0091  *
0092  * When adding the new extcon property, they *must* have
0093  * the type/value/default information. Also, you *have to*
0094  * modify the EXTCON_PROP_[type]_START/END definitions
0095  * which mean the range of the supported properties
0096  * for each extcon type.
0097  *
0098  * The naming style of property
0099  * : EXTCON_PROP_[type]_[property name]
0100  *
0101  * EXTCON_PROP_USB_[property name]  : USB property
0102  * EXTCON_PROP_CHG_[property name]  : Charger property
0103  * EXTCON_PROP_JACK_[property name] : Jack property
0104  * EXTCON_PROP_DISP_[property name] : Display property
0105  */
0106 
0107 /*
0108  * Properties of EXTCON_TYPE_USB.
0109  *
0110  * - EXTCON_PROP_USB_VBUS
0111  * @type:   integer (intval)
0112  * @value:  0 (low) or 1 (high)
0113  * @default:    0 (low)
0114  * - EXTCON_PROP_USB_TYPEC_POLARITY
0115  * @type:   integer (intval)
0116  * @value:  0 (normal) or 1 (flip)
0117  * @default:    0 (normal)
0118  * - EXTCON_PROP_USB_SS (SuperSpeed)
0119  * @type:       integer (intval)
0120  * @value:      0 (USB/USB2) or 1 (USB3)
0121  * @default:    0 (USB/USB2)
0122  *
0123  */
0124 #define EXTCON_PROP_USB_VBUS        0
0125 #define EXTCON_PROP_USB_TYPEC_POLARITY  1
0126 #define EXTCON_PROP_USB_SS      2
0127 
0128 #define EXTCON_PROP_USB_MIN     0
0129 #define EXTCON_PROP_USB_MAX     2
0130 #define EXTCON_PROP_USB_CNT (EXTCON_PROP_USB_MAX - EXTCON_PROP_USB_MIN + 1)
0131 
0132 /* Properties of EXTCON_TYPE_CHG. */
0133 #define EXTCON_PROP_CHG_MIN     50
0134 #define EXTCON_PROP_CHG_MAX     50
0135 #define EXTCON_PROP_CHG_CNT (EXTCON_PROP_CHG_MAX - EXTCON_PROP_CHG_MIN + 1)
0136 
0137 /* Properties of EXTCON_TYPE_JACK. */
0138 #define EXTCON_PROP_JACK_MIN        100
0139 #define EXTCON_PROP_JACK_MAX        100
0140 #define EXTCON_PROP_JACK_CNT (EXTCON_PROP_JACK_MAX - EXTCON_PROP_JACK_MIN + 1)
0141 
0142 /*
0143  * Properties of EXTCON_TYPE_DISP.
0144  *
0145  * - EXTCON_PROP_DISP_HPD (Hot Plug Detect)
0146  * @type:       integer (intval)
0147  * @value:      0 (no hpd) or 1 (hpd)
0148  * @default:    0 (no hpd)
0149  *
0150  */
0151 #define EXTCON_PROP_DISP_HPD        150
0152 
0153 /* Properties of EXTCON_TYPE_DISP. */
0154 #define EXTCON_PROP_DISP_MIN        150
0155 #define EXTCON_PROP_DISP_MAX        151
0156 #define EXTCON_PROP_DISP_CNT (EXTCON_PROP_DISP_MAX - EXTCON_PROP_DISP_MIN + 1)
0157 
0158 /*
0159  * Define the type of property's value.
0160  *
0161  * Define the property's value as union type. Because each property
0162  * would need the different data type to store it.
0163  */
0164 union extcon_property_value {
0165     int intval; /* type : integer (intval) */
0166 };
0167 
0168 struct extcon_dev;
0169 
0170 #if IS_ENABLED(CONFIG_EXTCON)
0171 /*
0172  * Following APIs get the connected state of each external connector.
0173  * The 'id' argument indicates the defined external connector.
0174  */
0175 int extcon_get_state(struct extcon_dev *edev, unsigned int id);
0176 
0177 /*
0178  * Following APIs get the property of each external connector.
0179  * The 'id' argument indicates the defined external connector
0180  * and the 'prop' indicates the extcon property.
0181  *
0182  * And extcon_get_property_capability() get the capability of the property
0183  * for each external connector. They are used to get the capability of the
0184  * property of each external connector based on the id and property.
0185  */
0186 int extcon_get_property(struct extcon_dev *edev, unsigned int id,
0187                 unsigned int prop,
0188                 union extcon_property_value *prop_val);
0189 int extcon_get_property_capability(struct extcon_dev *edev,
0190                 unsigned int id, unsigned int prop);
0191 
0192 /*
0193  * Following APIs register the notifier block in order to detect
0194  * the change of both state and property value for each external connector.
0195  *
0196  * extcon_register_notifier(*edev, id, *nb) : Register a notifier block
0197  *          for specific external connector of the extcon.
0198  * extcon_register_notifier_all(*edev, *nb) : Register a notifier block
0199  *          for all supported external connectors of the extcon.
0200  */
0201 int extcon_register_notifier(struct extcon_dev *edev, unsigned int id,
0202                 struct notifier_block *nb);
0203 int extcon_unregister_notifier(struct extcon_dev *edev, unsigned int id,
0204                 struct notifier_block *nb);
0205 int devm_extcon_register_notifier(struct device *dev,
0206                 struct extcon_dev *edev, unsigned int id,
0207                 struct notifier_block *nb);
0208 void devm_extcon_unregister_notifier(struct device *dev,
0209                 struct extcon_dev *edev, unsigned int id,
0210                 struct notifier_block *nb);
0211 
0212 int extcon_register_notifier_all(struct extcon_dev *edev,
0213                 struct notifier_block *nb);
0214 int extcon_unregister_notifier_all(struct extcon_dev *edev,
0215                 struct notifier_block *nb);
0216 int devm_extcon_register_notifier_all(struct device *dev,
0217                 struct extcon_dev *edev,
0218                 struct notifier_block *nb);
0219 void devm_extcon_unregister_notifier_all(struct device *dev,
0220                 struct extcon_dev *edev,
0221                 struct notifier_block *nb);
0222 
0223 /*
0224  * Following APIs get the extcon_dev from devicetree or by through extcon name.
0225  */
0226 struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name);
0227 struct extcon_dev *extcon_find_edev_by_node(struct device_node *node);
0228 struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev,
0229                              int index);
0230 
0231 /* Following API get the name of extcon device. */
0232 const char *extcon_get_edev_name(struct extcon_dev *edev);
0233 
0234 #else /* CONFIG_EXTCON */
0235 static inline int extcon_get_state(struct extcon_dev *edev, unsigned int id)
0236 {
0237     return 0;
0238 }
0239 
0240 static inline int extcon_get_property(struct extcon_dev *edev, unsigned int id,
0241                 unsigned int prop,
0242                 union extcon_property_value *prop_val)
0243 {
0244     return 0;
0245 }
0246 
0247 static inline int extcon_get_property_capability(struct extcon_dev *edev,
0248                 unsigned int id, unsigned int prop)
0249 {
0250     return 0;
0251 }
0252 
0253 static inline int extcon_register_notifier(struct extcon_dev *edev,
0254                 unsigned int id, struct notifier_block *nb)
0255 {
0256     return 0;
0257 }
0258 
0259 static inline int extcon_unregister_notifier(struct extcon_dev *edev,
0260                 unsigned int id, struct notifier_block *nb)
0261 {
0262     return 0;
0263 }
0264 
0265 static inline int devm_extcon_register_notifier(struct device *dev,
0266                 struct extcon_dev *edev, unsigned int id,
0267                 struct notifier_block *nb)
0268 {
0269     return -ENOSYS;
0270 }
0271 
0272 static inline  void devm_extcon_unregister_notifier(struct device *dev,
0273                 struct extcon_dev *edev, unsigned int id,
0274                 struct notifier_block *nb) { }
0275 
0276 static inline int extcon_register_notifier_all(struct extcon_dev *edev,
0277                            struct notifier_block *nb)
0278 {
0279     return 0;
0280 }
0281 
0282 static inline int extcon_unregister_notifier_all(struct extcon_dev *edev,
0283                          struct notifier_block *nb)
0284 {
0285     return 0;
0286 }
0287 
0288 static inline int devm_extcon_register_notifier_all(struct device *dev,
0289                             struct extcon_dev *edev,
0290                             struct notifier_block *nb)
0291 {
0292     return 0;
0293 }
0294 
0295 static inline void devm_extcon_unregister_notifier_all(struct device *dev,
0296                                struct extcon_dev *edev,
0297                                struct notifier_block *nb) { }
0298 
0299 static inline struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
0300 {
0301     return NULL;
0302 }
0303 
0304 static inline struct extcon_dev *extcon_find_edev_by_node(struct device_node *node)
0305 {
0306     return ERR_PTR(-ENODEV);
0307 }
0308 
0309 static inline struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev,
0310                 int index)
0311 {
0312     return ERR_PTR(-ENODEV);
0313 }
0314 
0315 static inline const char *extcon_get_edev_name(struct extcon_dev *edev)
0316 {
0317     return NULL;
0318 }
0319 #endif /* CONFIG_EXTCON */
0320 
0321 /*
0322  * Following structure and API are deprecated. EXTCON remains the function
0323  * definition to prevent the build break.
0324  */
0325 struct extcon_specific_cable_nb {
0326        struct notifier_block *user_nb;
0327        int cable_index;
0328        struct extcon_dev *edev;
0329        unsigned long previous_value;
0330 };
0331 
0332 static inline int extcon_register_interest(struct extcon_specific_cable_nb *obj,
0333                 const char *extcon_name, const char *cable_name,
0334                 struct notifier_block *nb)
0335 {
0336     return -EINVAL;
0337 }
0338 
0339 static inline int extcon_unregister_interest(struct extcon_specific_cable_nb *obj)
0340 {
0341     return -EINVAL;
0342 }
0343 #endif /* __LINUX_EXTCON_H__ */