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