xref: /openbmc/linux/drivers/extcon/extcon.h (revision 882cdb06)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_EXTCON_INTERNAL_H__
3 #define __LINUX_EXTCON_INTERNAL_H__
4 
5 #include <linux/extcon-provider.h>
6 
7 /**
8  * struct extcon_dev - An extcon device represents one external connector.
9  * @name:		The name of this extcon device. Parent device name is
10  *			used if NULL.
11  * @supported_cable:	Array of supported cable names ending with EXTCON_NONE.
12  *			If supported_cable is NULL, cable name related APIs
13  *			are disabled.
14  * @mutually_exclusive:	Array of mutually exclusive set of cables that cannot
15  *			be attached simultaneously. The array should be
16  *			ending with 0 or be NULL (no mutually exclusive cables).
17  *			For example, if it is {0x7, 0x30, 0}, then,
18  *			{0, 1}, {0, 1, 2}, {0, 2}, {1, 2}, or {4, 5} cannot
19  *			be attached simulataneously. {0x7, 0} is equivalent to
20  *			{0x3, 0x6, 0x5, 0}. If it is {0xFFFFFFFF, 0}, there
21  *			can be no simultaneous connections.
22  * @dev:		Device of this extcon.
23  * @id:			Unique device ID of this extcon.
24  * @state:		Attach/detach state of this extcon. Do not provide at
25  *			register-time.
26  * @nh_all:		Notifier for the state change events for all supported
27  *			external connectors from this extcon.
28  * @nh:			Notifier for the state change events from this extcon
29  * @entry:		To support list of extcon devices so that users can
30  *			search for extcon devices based on the extcon name.
31  * @lock:		Protects device state and serialises device registration
32  * @max_supported:	Internal value to store the number of cables.
33  * @extcon_dev_type:	Device_type struct to provide attribute_groups
34  *			customized for each extcon device.
35  * @cables:		Sysfs subdirectories. Each represents one cable.
36  *
37  * In most cases, users only need to provide "User initializing data" of
38  * this struct when registering an extcon. In some exceptional cases,
39  * optional callbacks may be needed. However, the values in "internal data"
40  * are overwritten by register function.
41  */
42 struct extcon_dev {
43 	/* Optional user initializing data */
44 	const char *name;
45 	const unsigned int *supported_cable;
46 	const u32 *mutually_exclusive;
47 
48 	/* Internal data. Please do not set. */
49 	struct device dev;
50 	unsigned int id;
51 	struct raw_notifier_head nh_all;
52 	struct raw_notifier_head *nh;
53 	struct list_head entry;
54 	int max_supported;
55 	spinlock_t lock;	/* could be called by irq handler */
56 	u32 state;
57 
58 	/* /sys/class/extcon/.../cable.n/... */
59 	struct device_type extcon_dev_type;
60 	struct extcon_cable *cables;
61 
62 	/* /sys/class/extcon/.../mutually_exclusive/... */
63 	struct attribute_group attr_g_muex;
64 	struct attribute **attrs_muex;
65 	struct device_attribute *d_attrs_muex;
66 };
67 
68 #endif /* __LINUX_EXTCON_INTERNAL_H__ */
69