View | Details | Raw Unified | Return to bug 1043231
Collapse All | Expand All

(-)a/drivers/extcon/extcon-adc-jack.c (-12 / +14 lines)
Lines 3-8 Link Here
3
 *
3
 *
4
 * Analog Jack extcon driver with ADC-based detection capability.
4
 * Analog Jack extcon driver with ADC-based detection capability.
5
 *
5
 *
6
 * Copyright (C) 2016 Samsung Electronics
7
 * Chanwoo Choi <cw00.choi@samsung.com>
8
 *
6
 * Copyright (C) 2012 Samsung Electronics
9
 * Copyright (C) 2012 Samsung Electronics
7
 * MyungJoo Ham <myungjoo.ham@samsung.com>
10
 * MyungJoo Ham <myungjoo.ham@samsung.com>
8
 *
11
 *
Lines 56-62 static void adc_jack_handler(struct work_struct *work) Link Here
56
	struct adc_jack_data *data = container_of(to_delayed_work(work),
59
	struct adc_jack_data *data = container_of(to_delayed_work(work),
57
			struct adc_jack_data,
60
			struct adc_jack_data,
58
			handler);
61
			handler);
59
	u32 state = 0;
62
	struct adc_jack_cond *def;
60
	int ret, adc_val;
63
	int ret, adc_val;
61
	int i;
64
	int i;
62
65
Lines 68-84 static void adc_jack_handler(struct work_struct *work) Link Here
68
71
69
	/* Get state from adc value with adc_conditions */
72
	/* Get state from adc value with adc_conditions */
70
	for (i = 0; i < data->num_conditions; i++) {
73
	for (i = 0; i < data->num_conditions; i++) {
71
		struct adc_jack_cond *def = &data->adc_conditions[i];
74
		def = &data->adc_conditions[i];
72
		if (!def->state)
73
			break;
74
		if (def->min_adc <= adc_val && def->max_adc >= adc_val) {
75
		if (def->min_adc <= adc_val && def->max_adc >= adc_val) {
75
			state = def->state;
76
			extcon_set_cable_state_(data->edev, def->id, true);
76
			break;
77
			return;
77
		}
78
		}
78
	}
79
	}
79
	/* if no def has met, it means state = 0 (no cables attached) */
80
80
81
	extcon_set_state(data->edev, state);
81
	/* Set the detached state if adc value is not included in the range */
82
	for (i = 0; i < data->num_conditions; i++) {
83
		def = &data->adc_conditions[i];
84
		extcon_set_cable_state_(data->edev, def->id, false);
85
	}
82
}
86
}
83
87
84
static irqreturn_t adc_jack_irq_thread(int irq, void *_data)
88
static irqreturn_t adc_jack_irq_thread(int irq, void *_data)
Lines 111-126 static int adc_jack_probe(struct platform_device *pdev) Link Here
111
		return -ENOMEM;
115
		return -ENOMEM;
112
	}
116
	}
113
117
114
	if (!pdata->adc_conditions ||
118
	if (!pdata->adc_conditions) {
115
			!pdata->adc_conditions[0].state) {
116
		dev_err(&pdev->dev, "error: adc_conditions not defined.\n");
119
		dev_err(&pdev->dev, "error: adc_conditions not defined.\n");
117
		return -EINVAL;
120
		return -EINVAL;
118
	}
121
	}
119
	data->adc_conditions = pdata->adc_conditions;
122
	data->adc_conditions = pdata->adc_conditions;
120
123
121
	/* Check the length of array and set num_conditions */
124
	/* Check the length of array and set num_conditions */
122
	for (i = 0; data->adc_conditions[i].state; i++)
125
	for (i = 0; data->adc_conditions[i].id != EXTCON_NONE; i++);
123
		;
124
	data->num_conditions = i;
126
	data->num_conditions = i;
125
127
126
	data->chan = iio_channel_get(&pdev->dev, pdata->consumer_channel);
128
	data->chan = iio_channel_get(&pdev->dev, pdata->consumer_channel);
(-)a/include/linux/extcon/extcon-adc-jack.h (-3 / +2 lines)
Lines 20-27 Link Here
20
20
21
/**
21
/**
22
 * struct adc_jack_cond - condition to use an extcon state
22
 * struct adc_jack_cond - condition to use an extcon state
23
 * @state:		the corresponding extcon state (if 0, this struct
24
 *			denotes the last adc_jack_cond element among the array)
23
 *			denotes the last adc_jack_cond element among the array)
24
 * @id:			the unique id of each external connector
25
 * @min_adc:		min adc value for this condition
25
 * @min_adc:		min adc value for this condition
26
 * @max_adc:		max adc value for this condition
26
 * @max_adc:		max adc value for this condition
27
 *
27
 *
Lines 33-39 Link Here
33
 * because when no adc_jack_cond is met, state = 0 is automatically chosen.
33
 * because when no adc_jack_cond is met, state = 0 is automatically chosen.
34
 */
34
 */
35
struct adc_jack_cond {
35
struct adc_jack_cond {
36
	u32 state;	/* extcon state value. 0 if invalid */
36
	unsigned int id;
37
	u32 min_adc;
37
	u32 min_adc;
38
	u32 max_adc;
38
	u32 max_adc;
39
};
39
};
40
- 

Return to bug 1043231