xref: /linux/include/linux/extcon/extcon-adc-jack.h (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
219939860Sanish kumar /*
319939860Sanish kumar  * include/linux/extcon/extcon-adc-jack.h
419939860Sanish kumar  *
519939860Sanish kumar  * Analog Jack extcon driver with ADC-based detection capability.
619939860Sanish kumar  *
719939860Sanish kumar  * Copyright (C) 2012 Samsung Electronics
819939860Sanish kumar  * MyungJoo Ham <myungjoo.ham@samsung.com>
919939860Sanish kumar  */
1019939860Sanish kumar 
1119939860Sanish kumar #ifndef _EXTCON_ADC_JACK_H_
1219939860Sanish kumar #define _EXTCON_ADC_JACK_H_ __FILE__
1319939860Sanish kumar 
1419939860Sanish kumar #include <linux/module.h>
1519939860Sanish kumar #include <linux/extcon.h>
1619939860Sanish kumar 
1719939860Sanish kumar /**
1819939860Sanish kumar  * struct adc_jack_cond - condition to use an extcon state
19a75e1c73SChanwoo Choi  *			denotes the last adc_jack_cond element among the array)
20a7da72eeSChanwoo Choi  * @id:			the unique id of each external connector
21a75e1c73SChanwoo Choi  * @min_adc:		min adc value for this condition
22a75e1c73SChanwoo Choi  * @max_adc:		max adc value for this condition
2319939860Sanish kumar  *
2419939860Sanish kumar  * For example, if { .state = 0x3, .min_adc = 100, .max_adc = 200}, it means
2519939860Sanish kumar  * that if ADC value is between (inclusive) 100 and 200, than the cable 0 and
2619939860Sanish kumar  * 1 are attached (1<<0 | 1<<1 == 0x3)
2719939860Sanish kumar  *
2819939860Sanish kumar  * Note that you don't need to describe condition for "no cable attached"
2919939860Sanish kumar  * because when no adc_jack_cond is met, state = 0 is automatically chosen.
3019939860Sanish kumar  */
3119939860Sanish kumar struct adc_jack_cond {
32a7da72eeSChanwoo Choi 	unsigned int id;
3319939860Sanish kumar 	u32 min_adc;
3419939860Sanish kumar 	u32 max_adc;
3519939860Sanish kumar };
3619939860Sanish kumar 
3719939860Sanish kumar /**
3819939860Sanish kumar  * struct adc_jack_pdata - platform data for adc jack device.
39a75e1c73SChanwoo Choi  * @name:		name of the extcon device. If null, "adc-jack" is used.
40a75e1c73SChanwoo Choi  * @consumer_channel:	Unique name to identify the channel on the consumer
4119939860Sanish kumar  *			side. This typically describes the channels used within
4219939860Sanish kumar  *			the consumer. E.g. 'battery_voltage'
432a9de9c0SChanwoo Choi  * @cable_names:	array of extcon id for supported cables.
44a75e1c73SChanwoo Choi  * @adc_contitions:	array of struct adc_jack_cond conditions ending
4519939860Sanish kumar  *			with .state = 0 entry. This describes how to decode
4619939860Sanish kumar  *			adc values into extcon state.
47a75e1c73SChanwoo Choi  * @irq_flags:		irq flags used for the @irq
48a75e1c73SChanwoo Choi  * @handling_delay_ms:	in some devices, we need to read ADC value some
4919939860Sanish kumar  *			milli-seconds after the interrupt occurs. You may
5019939860Sanish kumar  *			describe such delays with @handling_delay_ms, which
5119939860Sanish kumar  *			is rounded-off by jiffies.
521b6cf310SVenkat Reddy Talla  * @wakeup_source:	flag to wake up the system for extcon events.
5319939860Sanish kumar  */
5419939860Sanish kumar struct adc_jack_pdata {
5519939860Sanish kumar 	const char *name;
5619939860Sanish kumar 	const char *consumer_channel;
57a75e1c73SChanwoo Choi 
588a522bf2SPeter Foley 	const unsigned int *cable_names;
59a75e1c73SChanwoo Choi 
6019939860Sanish kumar 	/* The last entry's state should be 0 */
6119939860Sanish kumar 	struct adc_jack_cond *adc_conditions;
6219939860Sanish kumar 
6319939860Sanish kumar 	unsigned long irq_flags;
6419939860Sanish kumar 	unsigned long handling_delay_ms; /* in ms */
651b6cf310SVenkat Reddy Talla 	bool wakeup_source;
6619939860Sanish kumar };
6719939860Sanish kumar 
6819939860Sanish kumar #endif /* _EXTCON_ADC_JACK_H */
69