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