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