MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame^] | 1 | /* |
| 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 | |
| 26 | /** |
| 27 | * struct extcon_dev - An extcon device represents one external connector. |
| 28 | * @name The name of this extcon device. Parent device name is used |
| 29 | * if NULL. |
| 30 | * @print_name An optional callback to override the method to print the |
| 31 | * name of the extcon device. |
| 32 | * @print_state An optional callback to override the method to print the |
| 33 | * status of the extcon device. |
| 34 | * @dev Device of this extcon. Do not provide at register-time. |
| 35 | * @state Attach/detach state of this extcon. Do not provide at |
| 36 | * register-time |
| 37 | * |
| 38 | * In most cases, users only need to provide "User initializing data" of |
| 39 | * this struct when registering an extcon. In some exceptional cases, |
| 40 | * optional callbacks may be needed. However, the values in "internal data" |
| 41 | * are overwritten by register function. |
| 42 | */ |
| 43 | struct extcon_dev { |
| 44 | /* --- Optional user initializing data --- */ |
| 45 | const char *name; |
| 46 | |
| 47 | /* --- Optional callbacks to override class functions --- */ |
| 48 | ssize_t (*print_name)(struct extcon_dev *edev, char *buf); |
| 49 | ssize_t (*print_state)(struct extcon_dev *edev, char *buf); |
| 50 | |
| 51 | /* --- Internal data. Please do not set. --- */ |
| 52 | struct device *dev; |
| 53 | u32 state; |
| 54 | }; |
| 55 | |
| 56 | #if IS_ENABLED(CONFIG_EXTCON) |
| 57 | extern int extcon_dev_register(struct extcon_dev *edev, struct device *dev); |
| 58 | extern void extcon_dev_unregister(struct extcon_dev *edev); |
| 59 | |
| 60 | static inline u32 extcon_get_state(struct extcon_dev *edev) |
| 61 | { |
| 62 | return edev->state; |
| 63 | } |
| 64 | |
| 65 | extern void extcon_set_state(struct extcon_dev *edev, u32 state); |
| 66 | #else /* CONFIG_EXTCON */ |
| 67 | static inline int extcon_dev_register(struct extcon_dev *edev, |
| 68 | struct device *dev) |
| 69 | { |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | static inline void extcon_dev_unregister(struct extcon_dev *edev) { } |
| 74 | |
| 75 | static inline u32 extcon_get_state(struct extcon_dev *edev) |
| 76 | { |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | static inline void extcon_set_state(struct extcon_dev *edev, u32 state) { } |
| 81 | #endif /* CONFIG_EXTCON */ |
| 82 | #endif /* __LINUX_EXTCON_H__ */ |