xref: /linux/include/linux/extcon/extcon-adc-jack.h (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * include/linux/extcon/extcon-adc-jack.h
4  *
5  * Analog Jack extcon driver with ADC-based detection capability.
6  *
7  * Copyright (C) 2012 Samsung Electronics
8  * MyungJoo Ham <myungjoo.ham@samsung.com>
9  */
10 
11 #ifndef _EXTCON_ADC_JACK_H_
12 #define _EXTCON_ADC_JACK_H_ __FILE__
13 
14 #include <linux/module.h>
15 #include <linux/extcon.h>
16 
17 /**
18  * struct adc_jack_cond - condition to use an extcon state
19  *			denotes the last adc_jack_cond element among the array)
20  * @id:			the unique id of each external connector
21  * @min_adc:		min adc value for this condition
22  * @max_adc:		max adc value for this condition
23  *
24  * For example, if { .state = 0x3, .min_adc = 100, .max_adc = 200}, it means
25  * that if ADC value is between (inclusive) 100 and 200, than the cable 0 and
26  * 1 are attached (1<<0 | 1<<1 == 0x3)
27  *
28  * Note that you don't need to describe condition for "no cable attached"
29  * because when no adc_jack_cond is met, state = 0 is automatically chosen.
30  */
31 struct adc_jack_cond {
32 	unsigned int id;
33 	u32 min_adc;
34 	u32 max_adc;
35 };
36 
37 /**
38  * struct adc_jack_pdata - platform data for adc jack device.
39  * @name:		name of the extcon device. If null, "adc-jack" is used.
40  * @consumer_channel:	Unique name to identify the channel on the consumer
41  *			side. This typically describes the channels used within
42  *			the consumer. E.g. 'battery_voltage'
43  * @cable_names:	array of extcon id for supported cables.
44  * @adc_contitions:	array of struct adc_jack_cond conditions ending
45  *			with .state = 0 entry. This describes how to decode
46  *			adc values into extcon state.
47  * @irq_flags:		irq flags used for the @irq
48  * @handling_delay_ms:	in some devices, we need to read ADC value some
49  *			milli-seconds after the interrupt occurs. You may
50  *			describe such delays with @handling_delay_ms, which
51  *			is rounded-off by jiffies.
52  * @wakeup_source:	flag to wake up the system for extcon events.
53  */
54 struct adc_jack_pdata {
55 	const char *name;
56 	const char *consumer_channel;
57 
58 	const unsigned int *cable_names;
59 
60 	/* The last entry's state should be 0 */
61 	struct adc_jack_cond *adc_conditions;
62 
63 	unsigned long irq_flags;
64 	unsigned long handling_delay_ms; /* in ms */
65 	bool wakeup_source;
66 };
67 
68 #endif /* _EXTCON_ADC_JACK_H */
69